#include <bits/stdc++.h>

#define ll long long

using namespace std;

void solve() {

    ll a, b;
    cin >> a >> b;

    if(b & 1) {
        cout << "-1" << endl;
        return;
    }

    if((a ^ 1) == b) {
        cout << 1 << " " << a << endl;
        return;
    }

    ll n = round(sqrt(a));
    if(!(n & 1))
        n--;
    for(ll x = n; x >= 3; x -= 2) {
        if(a % x == 0) {
            ll y = a / x;

            if((x ^ y) == b) {
                cout << x << " " << y << endl;
                return;
            }
        }
    }

    cout << "-1" << endl;
}

int main() {

    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int t;
    cin >> t;

    while(t--)
        solve();

    return 0;
}