#include <bits/stdc++.h>
using namespace std;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

	int t;
	cin >> t;
	long long a[t],b[t],x[t],y[t];
	for(int i = 0; i < t; i++){
		cin >> a[i] >> b[i];
		x[i] = y[i] = 0;
		for(int q = sqrt(a[i]); q > 2; q -= 2){
			q -= q%2 - 1;
			if(a[i]%q == 0){
				if((b[i]^q) == a[i]/q){
					x[i] = q;
					y[i] = b[i]^q;
					break;
				}
			}
		}
	}
	for(int i = 0; i < t; i++){
		if(x[i] == 0) cout << -1 << "\n";
		else cout << x[i] << " " << y[i] << "\n";
	}

	return 0;
}