Implemented complex queries.

Queries are converted to CNF and quantifiers are grounded.