#include <bits/stdc++.h>

using namespace std;

#define pii pair<int,int>
#define ll long long
#define s second
#define f first

ll a,b,x,y,T;
bool breakovo;

int main(){
  cin >> T;
  while(T--){
    cin >> a >> b;
    breakovo=false;
    for(int i=1;i*i<=a;i+=2){
        if(a%i==0){
            ll xr=(i)^(a/i);
            if(xr==b){
                cout << i << " " << a/i << endl;
                breakovo=true;
                break;
            }
        }
    }
    if(!breakovo){
        cout << -1 << endl;
    }
  }
  return 0;
}