#include <iostream>
#include <cmath>
using namespace std;

int main(){
int n,p;
	cin>>n;
	long long a[n],b[n];
	for(int i=0;i<n;i++){
		cin>>a[i];
		cin>>b[i];
	}
	for(int i=0;i<n;i++){
		p=0;
		for(long long j=1;j<sqrt(a[i])+1;j++){
			if(a[i]%j==0){
				long long k=a[i]/j;
				long long c=j^k;
				if(c==b[i]){
					p=1;
					cout<<j<<" "<<k<<endl;
					break;
				}
			}
		}
		if(p==0)
		cout<<-1<<endl;
	}
	}