import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.StringTokenizer; public class Main { static int N = 100000; static int[] pri = new int[N + 1]; static boolean[] isprime = new boolean[N + 1]; static int cnt = 0; public static void main(String[] args) { FastReader sc = new FastReader(); int T = sc.nextInt(); prime(); while (T-- > 0) { int x = -1, y = -1; int a = sc.nextInt(); int b = sc.nextInt(); if(a == 1 && b == 1){ System.out.println(x + " " + y); continue; } if (Math.abs(a - b) == 1) { System.out.println(x + " " + y); continue; } int mm = Math.min(a, b); for (int i = 0; i < cnt && pri[i] <= mm; i++) { if (a % pri[i] == b % pri[i]) { x = pri[i]; break; } } if (a == b) { if(x == -1){ x = a; } y = a; System.out.println(x + " " + y); continue; } y = Math.abs(a - b); if(x == -1){ x = y; } System.out.println(x + " " + y); } } private static void prime() { isprime[0] = true; isprime[1] = true; for (int i = 2; i <= N; i++) { if (!isprime[i]) { pri[cnt++] = i; } for (int j = 0; j < cnt && i * pri[j] <= N; j++) { isprime[i * pri[j]] = true; if (i % pri[j] == 0) { break; } } } } static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader( new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } int[] arrayIn(int n) throws IOException { int arr[] = new int[n]; for (int i = 0; i < n; i++) { arr[i] = nextInt(); } return arr; } } public static void printarr(int[] arr) { for (int i = 0; i < arr.length; i++) { System.out.print(arr[i] + " "); } } }