#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <cmath>

bool isPerfectSquare(long double x)
{
    return ((x - (long long)(x)) == 0);
}

int get2na(long long broj)
{
    int i;
    for(i = 0; broj > 0; i++)
    {
        broj /= 2;
    }
    return i;
}

long long dvaNaNFunc(int n)
{
    long long res = 1;
    for(int i = 0; i < n; i++)
    {
        res *= 2;
    }
    return res;
}

int main()
{
    int T;
    long long A, B;
    scanf("%d",&T);
    for(int i = 0; i < T; i++)
    {
        scanf("%lld %lld",&A,&B);
        if(B % 2 == 1)
        {
            printf("-1\n");
        }
        else if(B == 0)
        {
            long double koren = sqrtl(A);
            if(isPerfectSquare(koren))
            {
                printf("%lld %lld\n", (long long) koren, (long long) koren);
            }
            else
            {
                printf("-1\n");
            }
        }
        else
        {
            long long koren = (long long) sqrtl(A);
            bool found = false;
            int n = get2na(B);
            long long dvaNaN = dvaNaNFunc(n);
            //long long dvaNaNminus1 = dvaNaNFunc(n - 1);
            for(long long i = dvaNaN + 1; i < koren; i += 2)
            {
                if(A % i == 0)
                {
                    long long j = A / i;
                    if(j^i == B)
                    {
                        printf("%lld %lld",i,j);
                        found = true;
                        break;
                    }
                }
            }
            if(!found)
            {
                printf("-1\n");
            }
        }
    }
}