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

vector<long long int> par(long long int a, long long int b) {
    vector<long long int> brojevi = {-1, -1};
    for (long long int i = 1; i <= sqrt(a); i+=2) {
        if (a%i ==0) {
                cout << "DELILAC: " << i << endl;
                //delioci.push_back(i);
                long long int del = a/i;
                long long int r = del^i;
                if (r == b) {
                        cout << "del^i is: " << r << endl;
                    brojevi = {del, i};
                    break;
            }
        }
    }
    return brojevi;
}


int main() {
    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;
}