#include <iostream>
#include <cmath>

using namespace std;

int main()
{
    int T;
    cin >> T;
    unsigned long long int y=pow(2,62), k, a[T][2], x, i, j;

    for(i=0;i<T;i++)
        for(j=0;j<2;j++)
            cin >> a[i][j];


    for(i=0;i<T;i++)
        {
            for(k=3; k<a[i][0]/2; k=k+2)
                if(a[i][0]%k==0)
                {
                    x=a[i][0]/k;
                    if((x^k)==a[i][1])
                        cout<<k<<" "<<x<<endl;
                    else
                        cout<<"-1"<<endl;

                    goto a;
                }
            a:x=x;
        }
}