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

using namespace std;

int main() {
    int t;
    cin >> t;
   
    unsigned long long a[t], b[t], x[t], y[t];
    
    for (int i= 0; i<t; i++) {
        cin>>a[i]>>b[i];
    }
    
    for (int j=0; j<t; j++) {
        for (y[j]=1; y[j]<=(floor(sqrt(a[j]))); y[j]+=2) {
            if(a[j]%y[j] == 0) {
               x[j] = a[j]/y[j];
               if((x[j] ^ y[j])==b[j]) {
                    break;
                }
            }
        }
    }
       
    for (int l=0; l<t; l++) {
        if ((x[l]^y[l])==b[l]) {
             cout<<x[l]<<" "<<y[l]<<"\n";
        }
        else {
            cout<<"-1";
        }
    }
   
    return 0;
}