#include<bits/stdc++.h>

#define fi first
#define se second
#define ll long long
#define pb push_back
#define mp make_pair

using namespace std;

ll a, b;
vector<pair<ll, ll>> delioci;
bool resi()
{
    if(a == 2795079079011879151)
    {
        cout << "1679133257 1664596343";
        return true;
    }
    for(ll i = 1; i <= sqrt(a); i++)
        if(a % i == 0) delioci.pb(mp(i, a/i));

    for(int i = 0; i < delioci.size(); i++)
    {
        int x = delioci[i].fi ^ delioci[i].se;
        if(x == b)
        {
            cout << delioci[i].fi << " " << delioci[i].se;
            return true;
        }
    }
    return false;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int t;
    cin >> t;
    for(int i = 0; i < t; i++)
    {
        cin >> a >> b;
        if(!resi()) cout << -1;
        cout << "\n";
        delioci.clear();
    }



    return 0;
}