#include <iostream>
#include <bits/stdc++.h>
#include <math.h>

using namespace std;

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

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

    unsigned long long matrica[n][2];

    for(int i=0;i<n;i++)
        for(int j=0;j<2;j++)
            cin>>matrica[i][j];

    /*unsigned long long Ai=10000000000000;
    unsigned long long Bi=10000000000000;

    cout<<Ai<<" "<<Bi<<"\n";
    //cin>>Ai>>Bi;
    //cout << "XOR is " << XOR(3,7)<<"\n";
    bool tf=false;
    for (unsigned long long i=1; i<=sqrt(Ai)&&!tf; i+=2)
    {
        if (Ai%i == 0)
        {
            if(Bi==XOR(i,Ai/i))
            {
                cout<<Ai/i<<" "<<i;
                tf=true;
            }
        }
    }
    if(!tf) cout<<-1;*/

    for(unsigned long long i=0;i<T;i++)
    {
        unsigned long long Ai = matrica[i][0];
        unsigned long long Bi = matrica[i][1];

        bool tf=false;
        for (long long i=1; i<=sqrt(Ai)&&!tf; i+=2)
        {
            if (Ai%i == 0)
            {
                if(Bi==XOR(i,Ai/i))
                {
                    cout<<Ai/i<<" "<<i<<"\n";
                    tf=true;
                }
            }
        }
        if(!tf)
            cout<<-1<<"\n";
    }

    return 0;
}