#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};
    int bc = log2(b) +1;
    long long int i = ceil(sqrt(a));
    if (i%2 ==0) {
        i++;
    }
    for (i; i >0; i-=2) {
        if (a%i ==0) {
                long long int del = a/i;
                int delc = log2(del) +1;
                int ic = log2(b) + 1;
                if (!((delc < bc && ic < bc))) {
                    long long int r = del^i;
                    if (r == b) {
                        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;
        vektorce.push_back({a,b});
    }
    for (long int i = 0; i< vektorce.size(); i++) {
        vector<long long int> vektor = par(vektorce[i][0],vektorce[i][1]);
        if (vektor[0] == -1) {
            cout << "-1" << endl;
        } else {
            cout << vektor[0] << " " << vektor[1] << endl;
        }
    }
    return 0;
}