#include <bits/stdc++.h>
using namespace std;
long long x,y;
vector<bool> bo ;
pair <long long,long long > nadji(long long a,long long b , int r) {
			pair <long long,long long > p ;
	for (int i = 1; i <= sqrt(a) ; i+=2 ) {
		if ( a % i == 0 ) {
			x = i ;
			y = a/i ;
			long long pom = x ^ y ;
			if ( pom == b ) {
				p.first = x;
				p.second = y;
				bo[r] = true ;
				return p ;
			}
		}
	}

	p.first = 0;
	p.second = 0;
	return p ;
}
int main () {
	int t ;
	cin >> t ;
	vector< pair <long long,long long > > v;
	long long a,b;

	for (int i = 0 ; i < t ; i++ ) {
		bo.push_back(false);
	}

	for (int i = 0 ; i < t ; i++ ) {
		cin >> a >> b ;
		v.push_back(nadji(a,b,i));
	}

	for (int i = 0 ; i < t ; i++ ) {
		if ( bo[i] )
		cout << v[i].first << ' ' << v[i].second << endl;
	else cout << -1 << endl ;
	}


}