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

#define ll long long

ll t;
ll a, b;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    cin >> t;

    while(t--){
        cin >> a >> b;

        if(b % 2){cout << -1 << "\n"; break;}
        bool broke = false;
        for(ll i = 1; i * i <= a; i += 2){
            if(a % i == 0 && a / i == (b ^ i)){
                cout << i << " " << a / i << "\n";
                broke = true;
                break;
            }
        }

        if(!broke){cout << -1 << "\n";}
    }

    return 0;
}