def create_node(name, phone):
    return {"name": name, "phone": phone, "left": None, "right": None}

def bst_insert(root, name, phone):
    if root is None:
        return create_node(name, phone)
    if name < root["name"]:
        root["left"] = bst_insert(root["left"], name, phone)
    elif name > root["name"]:
        root["right"] = bst_insert(root["right"], name, phone)
    else: 
        root["phone"] = phone 
    return root

def bst_insert_sort(sorted_data, left, right):
    if left > right:
        return None
    mid = (left + right) // 2
    name, phone = sorted_data[mid]
    root = create_node(name, phone)
    root["left"] = bst_insert_sort(sorted_data, left, mid - 1)
    root["right"] = bst_insert_sort(sorted_data, mid + 1, right)
    return root

def bst_find(root, name):
    if root is None:
        return None
    if name == root["name"]:
        return root["phone"]
    if name < root["name"]:
        return bst_find(root["left"], name)
    return bst_find(root["right"], name)

def bst_delete(root, name):
    if root is None:
        return None
    if name < root["name"]: 
        root["left"] = bst_delete(root["left"], name)
    elif name > root["name"]: 
        root["right"] = bst_delete(root["right"], name)
    else:
        # Нет детей или только один ребенок
        if root["left"] is None:
            return root["right"]
        if root["right"] is None:
            return root["left"]

        # Два ребенка
        current = root["right"]
        while current["left"] is not None:
            current = current["left"]
        
        root["name"] = current["name"]
        root["phone"] = current["phone"]
        # Удаляем преемника
        root["right"] = bst_delete(root["right"], current["name"])
        
    return root