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

int main()
{
    int t;
    scanf("%d",&t);
    long long a[t],b[t];
    for (int i=0;i<t;i++) scanf("%lld%lld",&a[i],&b[i]);
    for (int i=0;i<t;i++)
    {
        int o=0;
        if (b[i]%2==1)
        {
            printf("-1\n");
            continue;
        }
        else
            for (long long j=1;j<=sqrt(a[i]);j+=2)
            {
                if (a[i]%j==0)
                    if ((j^(a[i]/j))==b[i])
                    {
                        printf("%lld %lld\n",j,a[i]/j);
                        o=1;
                        break;
                    }
            }
        if (o==0) printf("-1\n");
    }
    return 0;
}