//Failure will never overtake me if my determination to succeed is strong enough
#include <bits/stdc++.h>

using namespace std;

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int t;
    cin >> t;
    while(t--)
    {
        long long a, b;
        cin >> a >> b;
        int x = -1, y = -1;
        for(int i = 1; i <= sqrt(a); i++)
        {
            if(a%i == 0 && (i^(a/i)) == b)
            {
                x = i;
                y = a/i;
                break;
            }
        }

        if(x != -1)
            cout << x << " " << y << "\n";
        else
            cout << -1;
    }
}