Implemented hybrid approach for solving problems with query.