#include<iostream>
#define MAX 10

using namespace std;

int main(void)
{
    unsigned long long niza[MAX],nizb[MAX],niza1[MAX];
    int n;

    cin>>n;

   for(int j=0;j<n;++j){
        cin>>niza[j]>>nizb[j];
        niza1[j] = niza[j];
    for(int i=1;i<=niza[j]/2;i+=2){
       if(niza[j]%i == 0 && ((niza[j]/i)^i) == nizb[j]){
           niza[j] /= i;
           nizb[j] = i;
           break;
           }
       
        }
        
   }


 for(int i=0;i<n;++i)
    if(niza1[i] == niza[i])
       cout<<-1<<endl;
    else
        cout<<nizb[i]<<" "<<niza[i]<<endl;


    return 0;
}