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

vector<long int> par(long int a, long int b) {
    vector<int> delioci;
    for (int i = 1; i <a/2+1; i++) {
        if (a%i ==0) {
            delioci.push_back(i);
        }
    }
    int i = 0;
    long int x = 1;
    long int y = a;
    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 int> brojevi;
    brojevi.push_back(x);
    brojevi.push_back(y);
    return brojevi;
}

int main() {
    int p;
    cin >> p;
    vector<vector<long int>> vektorce;
    for (int i = 0; i<p; i++) {
        long int a,b;
        cin >> a >> b;
        vector<long int> n = par(a, b);
        vektorce.push_back(n);
    }
    for (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;
}