package PTACZW;
import java.util.Scanner;
import java.util.ArrayList;
import java.io.*;
import java.util.StringTokenizer;
public class Main{
static BufferedReader reader=new BufferedReader(new InputStreamReader(System.in));
static PrintWriter pw=new PrintWriter(new OutputStreamWriter(System.out));
static StringTokenizer tokenizer=new StringTokenizer("");
static String next() throws IOException {
while (!tokenizer.hasMoreTokens()) {
tokenizer = new StringTokenizer(reader.readLine());
}
return tokenizer.nextToken();
}
static int nextInt() throws IOException
{
return Integer.parseInt(next());
}
static double Double() throws IOException
{
return Double.parseDouble(next());
}
static long nextlong() throws IOException
{
return Long.parseLong(next());
}
public static void main(String[] args)throws IOException {
ArrayList<Integer>list=new ArrayList<>();
ArrayList<Integer>ans=new ArrayList<>();
int n=nextInt();
while(n-->0)
{
int a=nextInt();
int b=nextInt();
int maxans=0;
int minans=0;
if(a<=b)
{
int temp;
temp=a;
a=b;
b=temp;
}
if(a>=b)
{
if(a==b)
{
if(a==1)
{
list.add(-1);
list.add(-1);
}
else {
list.add(2);
list.add(a);
}
}
else {
list.add(fac(a-b));
list.add(a-b);
}
}
else if(a-b==1)
{
list.add(-1);
list.add(-1);
}
}
for(int i=0;i<list.size();i++)
{
if(list.get(i)<=1)
{
ans.add(-1);
}
else {
ans.add(list.get(i));
}
}
int cn=0;
for(int i=0;i<ans.size();i++)
{
cn++;
pw.print(ans.get(i)+" ");
if(cn==2)
{
pw.println();
cn=0;
}
}
pw.flush();
}
public static int fac(int x)
{
if (x <= 1) {
return 1; // 1 has no prime factors
}
for (int i = 2; i <= Math.sqrt(x); i++) {
if (x % i == 0) {
return i; // i is the smallest prime factor
}
}
return x; // number itself is a prime number
}
}