#include <iostream>

using namespace std;

int main(){
	unsigned long long int a;
	unsigned long long int b;
	unsigned long long int x;
	unsigned long long int y;
	unsigned long long int z;
	unsigned long long int c;
	
	
	unsigned long int t;
	cin>>t;
	
	for(int i=1;i<=t;i++){
		cin>>a>>b;
		x=2;
		
		while(a % x !=0){
			x++;
			
		}
		
		y=a / x;
		
		z= x ^ y;
		if(z==b){
			cout<<x<<' '<<y<<endl;
		}else{
		
		if(z>=b){
		
		for(i=2;i<b;i++){
			while((z%i==0 && b%i==0)||z==b){
				b/=i;
				z/=i;
			}
			
			
		}
			cout<< x*b << ' '<<a/(x*b)<<endl;
		}else{
			cout<<-1<<endl;
		}
		}
	}
	
}