#include <bits/stdc++.h>

using namespace std;

#define int ll
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<double> vd;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<pi> vp;
typedef vector<pl> vpl;

signed main()
{
    ios_base::sync_with_stdio(false); 
    cin.tie(nullptr); 
    cout.tie(nullptr); 
    cerr.tie(nullptr);    

    int t;
    cin >> t;

    for (int e = 0; e < t; ++e){
        int a, b;
        cin >> a >> b;

        if (a == 0){
            cout << b << " 0\n";
            continue;
        }

        if (a == 1){
            int y = (b^1ll);

            cout << y << " 1\n";
            continue;
        }

        vi d;
        for (int i = 2; i <= sqrt(a) + 3; ++i){
            if (a % i == 0){
                d.push_back(i);
            }
        }

        pi sol = {-1, -1};
        for (auto& i : d){
            int j = a / i;

            if ((i^j) == b){
                sol = {i, j};
                break; 
            }
        }

        if (sol.first == -1)
            cout << "-1\n";
        else
            cout << sol.first << ' ' << sol.second << '\n';
    }
}