#include<bits/stdc++.h>
#define exit(n) {cout << n << endl;return;}
using namespace std;
typedef long long ll;
const int maxn = 1000005;
void Solve()
{
    ll s, x;
    cin >> s >> x;
    if(x == 0){
        ll a=sqrt(s);
        if(a*a == s){cout << a << " " << a << endl;return;}
        else exit(-1);
    }
    if(s == 0){cout << 0 << " " << x << endl;return;}
    for(int i=2;i<=s/2;i++){
        if(s%i != 0)continue;
        if((s/i)^i == x){
            cout << s/i << " " << i << endl;
            return;
        }
    }
    cout << -1 << endl;

}
int main()
{
    int t;
    cin >> t;
    while(t--)Solve();
    return 0;
}