Solve the queries