#include <iostream>
#include <cstring>
#include <cmath>

using namespace std;

unsigned long long a, b;

void solve(void)
{
    cin >> a >> b;

    if(b%2)
    {
        cout << -1;
        return;
    }
    if( b == 0 )
    {
        if( a%3 && (a+1)%3 )
        {
            cout << -1;
            return;
        }
        unsigned long long p = sqrt(a);
        cout << p << " " << p << endl;
        return;
    }
    unsigned long long p = a, q = 1, i = 3;
    while( q*q < a )
    {
        if( b == (p^q) )
        {
            cout << p << " " << q <<endl;
            return;
        }
        if( p%i )
            i+=2;
        else
        {
            p /= i;
            q *= i;
        }
    }
    cout << -1;
    return;
}

int main(void)
{
    int t;

    cin >> t;

    while( t-- )
        solve();

    return 0;
}