#include <iostream>
#include <vector>

using namespace std;



int main() {
	int n;
	vector <long long> num;
	cin >> n;
	n*=2;
	for(long long i = 0; i < n; i++) {
		long long x;
		cin >> x;
		num.push_back(x);
	}
	
	for(long long i = 0; i < n; i+=2) {
		bool res = false;
		long long x = num[i];
		for(long long j = 1; j < x / 2; j+=2) {
			int y = j^(x/j);
			if(x%j == 0 && y == num[i+1]) {
				cout << j << " " << (x/j) << endl;
				res = true;
				j = x/2;
			}
		}
		if(res == false) cout << -1 << endl;
	}
	return 0;	
}