#include <iostream>
#include <vector>

using namespace std;

bool delioci(long long& X, long long& Y, long long A, long long B){
    for(int i = 1; i <= A; i++){
        if(A % i == 0){
            X = i;
            Y = A / i;
            int pom = X ^ Y;
            if(B == pom){
                //ima = true;
                //cout << "beskonacna petlja 1" << endl;
                return true;
            }
            //cout << "beskonacna petlja 2" << endl;
        }
        //cout << "beskonacna petlja 3" << endl;
    }
    //cout << "beskonacna petlja 4" << endl;
    return false;
}

int main()
{
    int t;
    cin >> t;
    vector <long long> a, b;
    for(int i = 0; i < t; i++){
        long long p, q;
        cin >> p >> q;
        a.push_back(p);
        b.push_back(q);
    }
    vector <long long> x, y;
    long long X = -1, Y = -1;
    //bool ima = false;
    for(int i = 0; i < t; i++){
        delioci(X, Y, a[i], b[i]);
        //cout << "besknacna petlja 5" << endl;
        if(delioci(X, Y, a[i], b[i])){
            x.push_back(X);
            y.push_back(Y);
        }
        else{
            x.push_back(-1);
            y.push_back(-1);
        }
    }
    for(int i = 0; i < t; i++){
        if(x[i] == -1){
            cout << -1 << endl;
        }
        else{
            cout << x[i] << " " << y[i] << endl;
        }
    }
    //cout << "Hello world!" << endl;
    return 0;
}