added query based pair matching