#include <bits/stdc++.h>
using namespace std;
long long  resenje(long long A , long long B)
{
    for(int i = 1;i <= sqrt(A); i++)
    {
        if(A%i==0)
        {
            if(B ==  (i^(A/i)))
                return i;
        }


    }
   return -1;

}
int main()
{
    int T;
    scanf("%d",&T );
    unsigned long long A[T], B , Ar [T];

for(int i = 0; i<T ;i++){
        scanf("%lld %lld", &A[i] ,&B);
        Ar[i] =resenje(A[i],B);
}

for(int i = 0; i<T ;i++){
    if(Ar[i] == -1)
        printf("%lld\n",Ar[i]);
    else
        printf("%lld %lld\n",Ar[i] , A[i]/Ar[i]);


 }
 return 0;
}