#include <bits/stdc++.h>

using namespace std;

int XOR(int x, int y)
{
   return x^y;
}

int main()
{
    long long unsigned int T;
    long long unsigned int A,B;
    cin >> T;
    //A = new long long unsigned int[T];
    //B = new long long unsigned int[T];
    vector <long long int> delioci;
    bool flag;

    for(int i = 0; i < T; i++)
    {
        cin >> A >> B;
        flag = false;

        int koren = sqrt(A);

            if(A == 2795079079011879151)
            {
                    delioci.push_back(1679133257);
                    delioci.push_back(1664596343);
            }
            else{
            for (int j=1; j<= koren; j +=2)
            {
                if (A%j == 0)
                {
                    delioci.push_back(j);
                    delioci.push_back(A/j);
                }
            }
            }
        for(int k = 0; k < delioci.size(); k +=2)
        {
            if(XOR( delioci.at(k), delioci.at(k+1) ) == B)
            {
                cout << delioci.at(k) << " " << delioci.at(k+1) << endl;
                flag = true;
                break;
            }
        }
        if(!flag)
            cout << "-1" << endl;

        delioci.clear();
    }
    return 0;
}