#include <iostream>

using namespace std;

int main()
{
    int T;
   
    cin >> T;
    unsigned long long int A[T], B[T], X[T], Y[T];
    for(int i = 0; i<T; ++i)
    {
       cin >> A[i] >> B[i];
    }
    int faktA[10000][T];
    for(int i = 0; i<T;i++)
    {
        unsigned long long int x = 0;
        X[i] = 1;
        for(unsigned long long int j = 1; j <= A[i]; ++j)
        {
            if(A[i] % j == 0)
            {
                faktA[i][x] = j;x++;
            }
            cout << j<<endl;
        }
        for(unsigned long long int z = 0; z<x; ++z)
        {
            for(unsigned long long int w = z; w<x; ++w)
            {
                if(((faktA[i][z]^faktA[i][w]) == B[i]) && (faktA[i][z]*faktA[i][w])== A[i])
                {
                    X[i] = faktA[i][z];
                    Y[i] = faktA[i][w];
                    cout << X[i] << " " << Y[i] << endl;
                }
            }
        }
        if(X[i] == 1) cout << -1 << endl;
    }


    return 0;
}