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

int main()
{
    long long t;
    scanf("%lld",&t);
    for (long long i=0;i<t;i++)
    {
        long long a,b;
        int obidjen=0;
        scanf("%lld%lld", &a,&b);
        if (b%2)
        {
            printf("-1\n");
            continue;
        }
        long long m=round(sqrt(a));
        for (long long j=1;j<=m;j++)
        {
            if ((a%j)==0)
            {
                if ((j^(a/j))==b)
                {
                    printf("%lld %lld\n",j,a/j);
                    obidjen=1;
                    break;
                }
            }
        }
    if (!obidjen) printf("-1\n");
    }
}