Write a function to handle a specific data structure, such as a linked list or tree.
Implement lowest_common_ancestor(root, p, q) for a binary search tree with unique integer values. Each node is represented as a dictionary with val, left, and right keys, and missing children are null. Return the integer value of the lowest node that is an ancestor of both p and q.
Assume both target values exist in the tree. Use the BST ordering property where possible.
def lowest_common_ancestor(root, p, q):