#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <math.h>
#include <algorithm>
using namespace std;
int po=0;
int cinioci(unsigned long long x,unsigned long long y, unsigned long long* a, unsigned long long *b,int n)
{
    for (unsigned long long i=1;i<=sqrt(x);i++)
    {
        if (x%i==0)
        {
            a[po]=i;
            b[po]=x/(a[po]);
            if (((a[po])^(b[po]))==y)
            {
                po++;
                return 1;
            }

        }
    }
    po++;
    return 0;
}


int main()
{
    int n;
    unsigned long long int x,y;
    scanf("%d",&n);
    unsigned long long int *a=(unsigned long long int*) calloc (n,sizeof(unsigned long long int));
    unsigned long long int *b=(unsigned long long int*) calloc (n,sizeof(unsigned long long int));
    int *p=(int*) calloc (n,sizeof(int));
    for (int i=0;i<n;i++)
    {
        a[i]=-1;
        b[i]=-1;
        scanf("%llu%llu",&x,&y);
        p[i]=cinioci(x,y,a,b,n);
    }
    for (int i=0;i<n;i++)
    {
            if (p[i]==1)
            {

            if (a[i]>=0) printf ("%llu %llu\n",a[i],b[i]) ;
            }
            else printf("-1\n");
    }
    return 0;
}