#include <iostream>
#include <cmath>

using namespace std;

int main()
{
    int t;
    cin >> t;
    long long *a = new long long[t];
    long long *b = new long long[t];
    for(int i = 0; i < t; i++){
        cin >> a[i];
        cin >> b[i];
    }
    for(int j = 0; j < t; j++){
        float koren = sqrt(a[j]);
        long long d = 1;
        bool g = false;
        while(d <= koren){
            if(a[j] % d == 0){
                long long p = a[j] / d;
                if((d ^ p) == b[j]){
                    g = true;
                    cout << p << " " << d << endl;
                    break;
                }
            }
            else d += 2;
        }
        if(g == false) cout << -1 << endl;
    }
    return 0;
}