#include <iostream>
#include <stdio.h>
#include <math.h>

using namespace std;

int main(){
    long long int a,b,x,y;
    int n,p=0;
    cin >> n;
    for(int j=0;j<n;j++)
    {
        cin >> a >> b;
        if(b%2) {break;}
        for(long long int i=sqrt(a);i>=1;i--)
        {
            if(a%i==0)
            {
                x=i; y=a/i;
                if((x^y)==b)
                {printf("%lld %lld\n",x,y);p=1;break;}
            }
        }
        if(p==0) printf("-1\n"); p=0;
    }

    return 0;
}