#include<iostream>
long long x[2000],y[2000];
long long fun(long long prvi,long long drugi){
	long long rez = 0;  
    for (int i = 63; i >= 0; i--)                      
    { 
       bool b1 = prvi & (1 << i); 
       bool b2 = drugi & (1 << i); 
    	bool provera = (b1 & b2) ? 0 : (b1 | b2);           
        rez <<= 1; 
        rez |= provera; 
    } 
    return rez; 
}
using namespace std;
int main(){
	int T,i;
	long long a,b,j=1;
	cin>>T;
	for(i=0;i<T;i++){
		x[i]=y[i]=-1;
		cin>>a>>b;
		while(j<a){
			if(a%j==0 && b==fun(a/j,j)){
				y[i]=j;
				x[i]=a/j;
				break;	
			}
			else j=j+2;
		}
		
	}
	for(i=0;i<T;i++){
		if(x[i]==y[i] && x[i]==-1){
			cout<<"-1";
		} 
		else {
			cout<<x[i]<<" "<<y[i];
		}
		if(i!=T-1) cout<<endl;
	}
}