#include <iostream>

/* run this program using the console pauser or add your own getch, system("pause") or input loop */
using namespace std;
int main(int argc, char** argv) {
		long long n,pos=1,x=0,y=0,c=0,d=0;
        int resenje=0;
        cin>>n;
        long long a[n]; 
        long long b[n]; 
        long long a1[n];
        long long b1[n]; 
        for (long long i = 0; i < n; i++)
        {
		cin>>a[i]>>b[i];
        }
        long long j = 0;
        for(long long z = 0; z < n; z++) {         
                while (resenje == 0)
                {    
                    x = a[j];
                    y = b[j];
                    if (x % pos == 0) c = pos;
                    else c = 0;
                    d = c ^ y;
                if (c * d == x) {
                    resenje = 1;
                    break;
                        } 
                    pos += 2;
                if (pos >= x) break;
                }
            if (resenje == 1) {
                a1[z] = c;
                b1[z] = d;
            }
            else
            {
                a1[z] = 0;
            }
            resenje = 0;
            j++;
            }
        for (long long i = 0; i < n; i++)
        {
            if (a1[i] != 0)
                cout<<a1[i] << " " << b1[i];
            else
                cout<<"-1";
        } 
	return 0;
}