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

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


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;
            for(long long i = 3; i < koren; i += 2)
            {
                if(A % i == 0)
                {
                    long long j = A / i;
                    if(j^i == B)
                    {
                        printf("%lld %lld",i,j);
                        bool found = true;
                        break;
                    }
                }
            }
            if(!found)
            {
                printf("-1\n");
            }
        }
    }
}