#include <bits/stdc++.h>
#define ll long long
using namespace std;
long long x,y,pom;

	vector<bool> bo;

pair< ll , ll  > pronadji ( ll a, ll b , int r) {
	pair< ll , ll > p ;
	for (int i = 1 ; i <= sqrt(a); i++ ) {
		if ( a % i == 0 ) {
			x = a/i ;
			y = i ;
			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 <ll, ll> > v;



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

	ll a,b;

	for (int i = 0 ; i < t; i++ ) {
		cin >> a >> b;
		v.push_back( pronadji(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;
	}
}