#include <bits/stdc++.h>

using namespace std;

typedef unsigned long long ll;

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);

    ll q;

    cin >> q;

    while(q--)
    {
        ll a,b;

        cin >> a >> b;

        if(b % 2 == 1)
        {
            cout << "-1";
            continue;
        }
        if(a - 1 == b)
        {
            cout << a << " 1\n";
            continue;
        }
        else if(b == 0)
        {
            cout << sqrt(a) << " " << sqrt(a) << "\n";
            continue;
        }

        bool out = false;
        if(a % 3 == 0)
        {
            ll x = (ll)(3^b);
            if(x*3 == a)
            {
                cout << x << " " << 3 << "\n";
                out = true;
                continue;
            }
        }

        ll i = sqrt(a);
        i -= i%6;
        for(i; i >= 6 ; i-=6)
        {
            if(a % (i-1) == 0)
            {
                i--;
                ll x = (ll)(i^b);
                if(x*i == a)
                {
                    cout << x << " " << i << "\n";
                    out = true;
                    break;
                }
            }
            else if(a % (i + 1) == 0)
            {
                i++;
                ll x = (ll)(i^b);
                if(x*i == a)
                {
                    cout << x << " " << i << "\n";
                    out = true;
                    break;
                }
            }
        }

        if(!out)
        {
            cout << "-1\n";
        }
    }
}