#include <iostream>

using namespace std;
int XOR(long long int n,long long int m){
	long long int k;
	k = n ^ m;
	return k;
}
int pro(long long int x,long long int y){
	int n;
	for(int i = 1;i < x / 2;i ++){
		if(x % i == 0){
			n = x / i;
			if(XOR(n,i)==y){
				return i;
			}
		} 
	}
	return -1;
}

int main (){
	int T;
	long long int LP[T*2];
	long long int p1,p2;
	cin >> T;
	for(int i = 0;i < 2 * T;i += 2){
		cin >> p1 >> p2;
		LP[i] = p1;
		LP[i+1] = p2;
	}
	for(int i = 0;i < 2 * T;i = i + 2){
		p1 = pro(LP[i],LP[i+1]);
		if(p1 != -1){
			p2 = LP[i] / p1;
			cout<<p1<<" "<<p2<<endl;
		}else{
			cout<<p1<<endl;
		}
	}
}