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

int main()
{
    int T;
    cin >> T;
    unsigned long long Ai, Bi, Xi, Yi;
    vector<int> v_Xi;
    vector<int> v_Yi;
    for(int p = 0; p < T; p++)
    {
        bool da_li_je_prosao = 0;
        cin >> Ai >> Bi;
        for(unsigned long long i = 1; i <= sqrt(Ai); i += 2)
        {
            if(Ai % i == 0)
            {
                unsigned long long drugi = Ai / i;
                if(Bi == (i ^ drugi))
                {
                    da_li_je_prosao = 1;
                    Xi = i;
                    Yi = Ai / i;
                    break;
                }
            }
        }
        if(da_li_je_prosao)
        {
            v_Xi.push_back(Xi);
            v_Yi.push_back(Yi);
        }
        else
        {
            v_Xi.push_back(-1);
            v_Yi.push_back(-1);
        }
    }
    for(int i = 0; i < v_Xi.size(); i++)
    {
        if(v_Xi[i] == -1)
        {
            cout << -1 << endl;
        }
        else
        {
            cout << v_Xi[i] << " " << v_Yi[i] << endl;
        }
    }
    return 0;
}