#include <iostream>
#include <cmath>

using namespace std;

int main()
{
    int T;
    cin>>T;

    long long A[T], B[T], X[T], Y[T];
    long long l;

    for(long long i = 0; i < T; i++)
    {
        cin>>A[i]>>B[i];
        for(long long j = 1; j <= sqrt(A[i]); j+=2)
        {
            if((A[i] % j == 0))
            {
                X[i] = A[i] / j;
                Y[i] = j;

                l = X[i] ^ Y[i];
                if(l != B[i])
                {
                    X[i] = -1;
                    Y[i] = -1;
                }
            }
        }

    }
    for(int i = 0; i < T; i++)
        {
            if(X[i] != -1 && Y[i] != -1)
                cout<<X[i]<<" "<<Y[i]<<endl;
            else
                cout<<-1<<endl;
        }

    return 0;
}