Fix queries like `(~a ~b) (~c ~d)` being handled like `~a ~b ~c ~d`. Caused by trimming AND nodes from the tree before rewriting the '~' operator, which caused `~a` terms to be incorrectly lifted out of subexpressions.