#include <stdio.h>
#include <math.h>

int main(void) {
  int t,i=0;
  long long int x=0;
  scanf("%d",&t);
  long long int b[t];
  long long int a[t];
  while(i++<t){
      scanf("%lld %lld",&a[i],&b[i]);
      
  }

  i = 0;

  while(i++<t){
    while(x++<sqrt(a[i])+1){
    if(a[i]%x || !(b[i]==(x^a[i]/x))) 
      continue;
  break;
  }
  if(x>=sqrt(a[i])+1)
    printf("\n-1");
  else printf("\n%lld %lld",x,a[i]/x);
  x=0;
  }
}