#include<bits/stdc++.h>
using namespace std;
int main(){
	long long t;
	cin>>t;
	long long a[t],b[t];
	for(long long i=0;i<t;i++)cin>>a[i]>>b[i];
	long long x,y;
	for(long long i=0;i<t;i++){
		x=(sqrt(b[i]*b[i]+4*a[i])+b[i])/2;
		y=a[i]/x;
		if(x*y!=a[i]){
		   long long koren=sqrt(a[i])+1;
		   long long pom=1;
		   bool resenje=false;
		   while(pom<=koren){
			    if(a[i]%pom==0&&b[i]==(pom^(a[i]/pom))){
				   resenje=true;
			 	   cout<<pom<<" "<<a[i]/pom<<endl;
				   break;
			    }
			    pom+=2;
		    }
		    if(!resenje)cout<<-1<<endl;
		}
		else cout<<x<<" "<<y<<endl;
	}
}