#include <iostream>
#include <stdio.h>
#include <math.h>

using namespace std;



int main(int argc, const char * argv[])
{
    int T ,i ;
    cin>>T;
    long long unsigned int A[T],B[T],m;
    for(i=0;i<T;i++)
    {
        cin>>A[i]>>B[i];
    }
    for (i = 0 ; i <T ; i ++ )
    {
    
    
        for (m=1;m<=(long long int)sqrtl(A[i]);m++)
        {
            if((A[i]%m)==0){
                if (((A[i]/m)^m)==B[i]){
                    cout<<m<<" ";
                    cout<<A[i]/m<<endl;
                
                    break;
                }
                if (m==(long long int)sqrtl(A[i]))
                {
                    cout<<-1<<endl;
                }
         }
        
        
        
        
        }
        
    }
   
    return 0;
}