#include <bits/stdc++.h>

using namespace std;

int XOR(int x, int y)
{
   return (x | y) & (~x | ~y);
}

float fastsqrt(float val) {
int tmp = *(int *)&val;
tmp -= 1<<23;
tmp = tmp >> 1;
tmp += 1<<29;
return *(float *)&tmp;
}

int main()
{
    //Deklarisanje puno stvari
    int T;
    long long unsigned int *A,*B;
    scanf("%i",&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++)
    {
        flag = false;
        scanf("%llu %llu",&A[i],&B[i]);
        //Unos svih delioca A od i
        int koren = sqrt(A[i]);
        for (int j=1; j<= koren; j++)
        {
            if (A[i]%j == 0)
            {
                delioci.push_back(j);
                delioci.push_back(A[i]/j);
            }
        }
        //Testiranje parova delioca
        for(int k = 0; k < delioci.size(); k +=2)
        {
            if(XOR( delioci.at(k), delioci.at(k+1) ) == B[i])
            {
                cout << delioci.at(k) << " " << delioci.at(k+1) << endl;
                flag = true;
                break;
            }
        }
        if(!flag)
            cout << "-1" << endl;
        delioci.clear();
    }
    return 0;
}