#include <iostream>
#include <limits.h>
#include <cmath>

long long unsigned n;

long long unsigned fin(long long unsigned a,long long unsigned b){
  long long unsigned lim=sqrt(a);
  for(long long unsigned i=3;i<=lim;i+=2)
    if(a%i==0 && ((i^b)==a/i))return i;
  return ULLONG_MAX;
}

int main(){
  std::ios::sync_with_stdio(false); 
  std::cin>>n;
  long long unsigned a[n][2];
  for(long long unsigned i=0;i<n;i++){
    std::cin>>a[i][0]>>a[i][1];
  }
  for(long long unsigned i=0;i<n;i++){
    long long unsigned re=fin(a[i][0],a[i][1]);
    if(re==ULLONG_MAX)std::cout<<-1<<'\n';
    else std::cout<<re<<' '<<(re^a[i][1])<<'\n';
  }
}