#include <iostream>
#include <cmath>

using namespace std;


int nadji(int x, int y)
{
   return (x | y) & (~x | ~y);
}

void stampaj(long long a, long long b)
{
    long long del1 = sqrt(a),del2;
    bool nasao = false;
    while (del1<=3*a)&& !nasao)
    {
        if (a%del1!=0) del1+=2;
        else
        {
            del2 = a/del1;
            if (nadji(del1,del2) == b)
            {
                cout <<del1 <<" " <<del2<<endl;;
                nasao = true;
            }
            del1+=2;
        }
    }
    if(!nasao)cout <<-1<<endl;
}



int main()
{
    int t;
    cin >>t;
    long long mat [t][2];
    for (int i = 0; i<t;i++)
        for (int j = 0; j<2; j++)
            cin >>mat[i][j];
    for (int i = 0; i<t; i++)
        stampaj(mat[i][0],mat[i][1]);
    return 0;
}