Implement query stack for query integration