time complexity of query1