#include <stdio.h>
#include <stdlib.h>
#include <vector>
using namespace std;
int main()
{
    long long int T;
    scanf("%lld",&T);
    long long int* a=(long long int*)calloc(T,sizeof(long long int));
    long long int* b=(long long int*)calloc(T,sizeof(long long int));
    long long int* x=(long long int*)calloc(T,sizeof(long long int));
    long long int* y=(long long int*)calloc(T,sizeof(long long int));
    
    for(long long int i=0;i<T;i++)
        scanf("%lld %lld",&a[i],&b[i]);
        
    vector <long long int> d[T];
    for(long long int i=0;i<T;i++)    
        for(long long int j=1;j<a[i];j++)
            if(a[i]%j==0)
                d[i].push_back(j);
    
    
    for(long long int i=0;i<T;i++)
        for(vector <long long int>  :: iterator it=d[i].begin();it!=d[i].end();it++)
        {
            //printf("%lld %lld %lld %lld\n",b[i],*it,a[i]/(*it),(a[i]/(*it))^(*it));
            if(a[i]%(*it)==0 && ((unsigned char)(a[i]/(*it))^(unsigned char)(*it))==b[i])
                {
                    //printf("%lld %lld\n",a[i]/(*it),*it);
                    x[i]=a[i]/(*it);
                    y[i]=*it;
                    i++;
                    it=d[i].begin();
                }
        }   
                
    for(long long int i=0;i<T;i++)
        if(x[i]==0 && y[i]==0)
            printf("%d\n",-1);
        else printf("%lld %lld\n",y[i],x[i]);
    return 0;
}