Define QuerySorter class to resolve the dependencies among queries