def lowest_common_ancestor(root, p, q):
while root:<EOL><INDENT>if p.val > root.val < q.val:<EOL><INDENT>root = root.right<EOL><DEDENT>elif p.val < root.val > q.val:<EOL><INDENT>root = root.left<EOL><DEDENT>else:<EOL><INDENT>return root<EOL><DEDENT><DEDENT>
:type root: Node
:type p: Node
:type q: Node
:rtype: Node