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

using namespace std;

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