#include <iostream>
#include <cmath>

using namespace std;

int t, gottem;
unsigned long long a[10001], b[10001], x ,y;

int main()
{
    
    cin >> t;

    for(int i = 0;i <t;i++)
        cin >> a[i] >> b[i];

    for(int i = 0;i <t;i++){
        gottem = 0;

        //cout << sqrt(a[i]) << endl;

        for(unsigned long long j = 2;j <= sqrt(a[i]);j++){
            if(a[i] % j == 0){
                //TRY J
                x = j;
                if((y = (b[i] ^ x) * x) == a[i]){
                    y = (b[i] ^ x);
                    cout << x << " " << y << endl;
                    gottem = 1;
                    break;
                }

                x = a[i] / x;

                if((y = (b[i] ^ x) * x) == a[i]){
                    y = (b[i] ^ x);
                    cout << x << " " << y << endl;
                    gottem = 1;
                    break;
                }
            }
        }

        if(gottem == 0)
            cout << -1 << endl;
    }

    return 0;
}