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

int nadji(unsigned long long int a[][2], unsigned long long int n, unsigned long long int *xi, unsigned long long int *yi){
    unsigned long long int j=2, temp, ksor, puta;
    temp=a[n][0];
    while (temp!=0 && j<a[n][0]){
        if (temp%j==0){
                temp/=j;
                *xi=temp;
                *yi=j;
                ksor=(*xi)^j;
                puta=(*xi)*j;
            if (ksor==a[n][1] && puta==a[n][0]){
                return 1;
            }

        }
                else j++;
    }
    return 0;
}

int main()
{
    unsigned long long int n, i, j, xi, yi;
    scanf ("%llu", &n);
    unsigned long long int a[n][2];
    for (i=0; i<n; i++){
        for (j=0; j<2; j++){
            scanf ("%llu", &a[i][j]);
        }
    }
    for (i=0; i<n; i++){
        if (nadji(a, i, &xi, &yi)) printf ("%llu %llu", xi, yi);
        else printf ("-1");
        printf ("\n");
    }
    return 0;
}