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

vector<long long int> par(long long int a, long long int b) {
    vector<long long int> delioci;
    for (long long int i = 1; i <= sqrt(a); i++) {
        if (a%i ==0) {
            delioci.push_back(i);
        }
    }
    int i = 0;
    long long int x = 1;
    long long int y = a;
    long long int broj = -1;
    while (b!= broj ) {
        i++;
        if (i >= delioci.size()) {
            x=-1;
            break;
        }
        x=delioci[i];
        y=a/x;
        //cout << "x is: " << x << " y is: " << y << endl;
        broj = x ^ y;
        //cout << "b is: " << b << " x^y is: " << broj << endl;
        if (b == broj) {
            break;
        }
    }
    //cout << "x is now: " << x << " and y: " << y << endl;
    vector<long long int> brojevi;
    brojevi.push_back(x);
    brojevi.push_back(y);
    return brojevi;
}


int main() {
    //long long int test = 2795079079011879151;
    //cout << test << endl;
    //long double bh = sqrtl(test);
    //cout << fixed << setprecision(30) << sqrtl(test) << endl;
    int p;
    cin >> p;
    vector<vector<long long int>> vektorce;
    for (long int i = 0; i<p; i++) {
        long long int a,b;
        cin >> a >> b;
        vector<long long int> n = par(a, b);
        vektorce.push_back(n);
    }
    for (long int i = 0; i< vektorce.size(); i++) {
        if (vektorce[i][0] == -1) {
            cout << "-1" << endl;
        } else {
            cout << vektorce[i][0] << " " << vektorce[i][1] << endl;
        }
    }
    return 0;
}