#include <iostream>

using namespace std;

int XxorY[70];

bool xxory(unsigned long long int xx, unsigned long long int yx, unsigned long long int bx) {
	int X[70], Y[70], B[70], brx, brb, bry;
	unsigned long long int x, y, b;
	bool flag;
	
	x = xx;
	y = yx;
	b = bx;
	
	for (int i = 0; i < 70; i++) {
		X[i] = 0;
		Y[i] = 0;
		B[i] = 0;
	}
	
	brx = 0;
	while(x >= 1) {
		
		if (x % 2 == 1){
			
			x -= 1;
			X[brx] = 1;
			
		}
		x = x / 2;
		brx++;
		
	}
	bry = 0;
	while(y >= 1) {
		
		if (y % 2 == 1){
			
			y -= 1;
			Y[bry] = 1;
			
		}
		y = y / 2;
		bry++;
		
	}
	brb = 0;
	while(b >= 1) {
		
		if (b % 2 == 1){
			
			b -= 1;
			B[brb] = 1;
			
		}
		b = b / 2;
		brb++;
		
	}
	
	brx = (brx > bry)? brx : bry;
	brx = (brx > brb)? brx : brb;
	
	for (int i = 0; i <= brx; i++) {
		
		if ((X[i] xor Y[i]) == B[i]) {
			
			flag = true;
			
		}
		else {
			
			flag = false;
			break;
			
		}
		
	}
	
	return flag;
}

int main() {
	
	unsigned long long int A, B, X[10000], Y[10000], delioci;
	int br = 0, t, flag[10000];
	bool f;
	cin >> t;
	
	for (int j = 0; j < t; j++){
	
		cin >> A >> B;
		f = true;
		
		for (unsigned long long int i = 1; i <= (A + 1) / 2; i++) {
		
			if ((A % i == 0) && (xxory(i, A/i, B))) {
				
				X[j] = i;
				Y[j] = A / i;
				f = false;
				break;
				
			}
		
		}
		
		if (f) {
			flag[br] = j;
			br++;
		}
	}
	
	br = 0;
	
	for (int i = 0; i < t; i++){
		
		if (i == flag[br]) {
			
			cout << "-1" << endl;
			br = br + 1; 
			
		}
		else cout << X[i] << " " << Y[i] << endl;
		
	}
	
	return 0;
}