#include <bits/stdc++.h>
using namespace std;


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    short i, t;
    cin >> t;
    long long koren, a[t], b[t], reza[t], rezb[t];
    for(i = 0; i < t; ++i){
        cin >> a[i] >> b[i];
    }
    for(i = 0; i < t; ++i){
        reza[i] = -1;
    }
    for(i = 0; i < t; ++i){
        for(koren = sqrtl(a[i]); koren > 0; koren--){
            if(a[i] % koren == 0 && ((a[i] / koren) ^ koren) == b[i]){
                reza[i] = koren;
                rezb[i] = a[i] / koren;
            }
        }
    }
    for(i = 0; i < t; ++i){
        if(reza[i] == -1){
            cout << -1 << endl;
        }
        else{
            cout << reza[i] << " " << rezb[i] << endl;
        }
    }
    return 0;
}