#include <stdio.h>
	int main(){  
		int t;
		int k,i;
		bool flag = false;
		scanf("%d",&t);
		long long a[t],b[t];
		long long x[t],y[t];
		for(int j=0;j<t;j++)
			scanf("%llu %llu",&a[j],&b[j]);
		
		for(i=0;i<t;i++){
			
			flag = false;
			for(k=1;k<=a[i]/2;k+=2){
				
				if(a[i]/float(k) == (long long)(a[i]/k)){
					x[i]=a[i]/k;
					y[i]=k;
					} 
				else continue;	
				if(a[i]==x[i]*y[i] && (long long)(x[i]^y[i])==b[i])
	
					flag= true;	
								
			}
		if (flag == true)
			break;
			
	}
	if (flag == false)
				printf("-1");
				else printf("%llu %llu\n",x[i],y[i]);

		
		
		
		return 0;
		
	}