#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], pom;
    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){
        if(b[i] % 2 == 1){
            continue;
        }
        koren = sqrtl(a[i]);
        if(koren % 2 == 0){
            koren--;
        }
        for(; koren > 0; koren -= 2){
            pom = a[i] / koren;
            if((b[i] ^ koren) == pom){
                reza[i] = koren;
                rezb[i] = pom;
                break;
            }
        }
    }
    for(i = 0; i < t; ++i){
        if(reza[i] == -1){
            cout << -1 << endl;
        }
        else{
            cout << reza[i] << " " << rezb[i] << endl;
        }
    }
    return 0;
}