#include <iostream>
#include <stdio.h>
#include <math.h>
using namespace std;

unsigned long long a[100], b[100], x[100], y[100];
bool pom[100];
int main()
{
    unsigned long long t, i, j;
    scanf("%llu", &t);

    for(i = 0; i < t; i++)
    {
        scanf("%llu %llu", a + i, b + i);
    }

    for(i = 0; i < t; i++)
    {
        pom[i] = true;

        for(j = 0; j <= sqrt(a[i]); j++)
            if(a[i] == ((b[i]^j)*j))
            {
                x[i] = j;
                pom[i] = false;
                break;
            }
            
        y[i] = a[i] / x[i];
    }

    for(i = 0; i < t; i++)
    {
        if(pom[i])
            printf("-1\n");
        else
            printf("%llu %llu\n", x[i], y[i]);
    }


    return 0;
}