#include <bits/stdc++.h>
using namespace std;
void Main(){
long long a,b;
cin >>a>>b;
for(long long i=1;i*i<=a;i++){
    if(a%i!=0)continue;
  //  cout <<"CANDIDATE:"<<i<<" "<<a/i<<endl;
    if((i^(a/i))==b){
        cout <<i<<" "<<a/i<<endl;
        return;
    }
}
cout <<-1<<endl;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cerr.tie(0);
int t;
cin >>t;
for(int i=0;i<t;i++){
    Main();
}
}
///  :(