#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

int main ()
{
    ios_base::sync_with_stdio(false);
    ll t; cin >> t;
    while(t--) {
        ll a, b, x=0; cin >> a >> b;
        if(b%2==0)
            for(ll i=1;i*i<=a;i+=2)
                if(a%i==0 && (i^(a/i)) == b) x=i;
        if(x) cout << x << " " << a/x << endl;
        else cout << -1 << endl;
    }
    return 0;
}