#include<bits/stdc++.h>

using namespace std;

int t;
long long a,b;

bool worksXor(long long x){
	return ((x ^ (a/x)) == b);
}

int main(){
	ios_base::sync_with_stdio(0);
	cout.tie(0);
	cin.tie(0);
	cin >> t;
	while(t--){
		bool ok = 0;
		cin >> a >> b;
		for(int i = 1; i*i <= a; ++i){
			if(a % i == 0 and worksXor(i)){
				cout << a/i << ' ' << i << '\n';
				ok = 1;
				break;
			}
		}
		if(!ok){
			cout << -1 << '\n';
		}
	}
}