def bst_insert(root, name, phone):
    new_node = {'name': name, 'phone': phone, 'left': None, 'right': None}

    if root is None:
        return new_node

    cur = root
    parent = None

    while cur is not None:
        parent = cur
        if name < cur['name']:
            cur = cur['left']
        elif name > cur['name']:
            cur = cur['right']
        else:
            cur['phone'] = phone
            return root

    if name < parent['name']:
        parent['left'] = new_node
    else:
        parent['right'] = new_node

    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_min(node):
    while node['left'] is not None:
        node = node['left']
    return node


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']

        successor = _bst_min(root['right'])
        root['name'], root['phone'] = successor['name'], successor['phone']
        root['right'] = bst_delete(root['right'], successor['name'])

    return root

def bst_list_all(root):
    if root is None:
        return []
    return bst_list_all(root['left']) + [(root['name'], root['phone'])] + bst_list_all(root['right'])