#include <iostream>
#include<bits/stdc++.h>
using namespace std;
vector<pair<long long,long long> > rez;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    bool moguce=false;
    int i,t;
    long long a,b,j,pom,p;
    cin >> t;
    for(i=0;i<t;i++)
    {
        cin >> a >> b;
        pom=(long long)sqrt(a);
        moguce=false;
        if(a>=b)
        {
            for(j=1;j<=pom;j++)
            {
                if(a%j==0)
                {
                    p=a/j;
                    if((p^j)==b)
                    {
                        moguce=true;
                        rez.push_back(make_pair(p,j));
                        break;
                    }
                }
            }
        }
        if(moguce==false)
            rez.push_back(make_pair(-1,-1));
    }
    for(i=0;i<t;i++)
    {
        if(rez[i].first==-1)
            cout << -1 << endl;
        else
            cout << rez[i].first << " " << rez[i].second << endl;
    }
    //cout << "Hello world!" << endl;
    return 0;
}