#include <stdio.h>
#include <math.h>
int main()
{
    int t,p;
    unsigned long k;
    scanf("%d",&t);
    unsigned long long niz1[t],niz2[t];
    
    for(int i=0;i<t;i++){
        scanf("%llu %llu",&niz1[i],&niz2[i]);
        
    }
    for(int i=0;i<t;i++){
        p=0;
        
        
        for(unsigned long j=(floor(sqrt(niz1[i])))+1;j>=1;j=j-1){
            
            if(niz2[i]%2==1){
                printf("-1 \n");
                p=1;
                break;
            }
            if(niz1[i]%j==0){
                k=niz1[i]/j;
                if((j^k)==niz2[i]){
                    printf("%lu %lu \n",j,k);
                    p=1;
                    break;
                    
                    
                }
                
            }
            
        }
        
      if(p==0){
          printf("-1 \n");
          
      }
        
    }
    
    return 0;
}