#include<iostream>
#include<cmath>
using namespace std;


//////
bool isPrime(int n)  
{  
    // Corner cases  
    if (n <= 1)  return false;  
    if (n <= 3)  return true;  
    
    // This is checked so that we can skip   
    // middle five numbers in below loop  
    if (n%2 == 0 || n%3 == 0) return false;  
    
    for (int i=5; i*i<=n; i=i+6)  
        if (n%i == 0 || n%(i+2) == 0)  
           return false;  
    
    return true;  
}  


int nextPrime(int N) 
{ 
  
    // Base case 
    if (N <= 1) 
        return 2; 
  
    int prime = N; 
    bool found = false; 
  
    // Loop continuously until isPrime returns 
    // true for a number greater than n 
    while (!found) { 
        prime++; 
  
        if (isPrime(prime)) 
            found = true; 
    } 
  
    return prime; 
} 
  
//////

int main()
{
    unsigned long long a[10000],b[10000];
    long t,t1,m,t2,x,y,k;
    m=0;


    cin>>t;
    for(t1=1;t1<=t;t1++)
    {
     k=0;
        cin>>a[t1];
        cin>>b[t1];
        m++;
        for(t2=1;t2<=sqrt(a[t1]);)
        {
            if(a[t1]%t2==0)
            {
                x=t2;
                y=a[t1]/t2;
                if(b[t1]==(x^y))
                {
                    cout<<endl<<x<<" ";
                    cout<<y;
                    k=1;
                    goto endloop;
                }
            }
////////////
 
t2=nextPrime(t2);
///cout << t2 << "_";

////////////
        }
        endloop:
        m++;
        if (k==0)
        {
            cout<<endl<<"-1";
        }

    }

}