using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp17
{
    class Program
    {
        static void Main(string[] args)
        {
            int p = int.Parse(Console.ReadLine());
            ulong[,] n = new ulong[p, 2];
            ulong[,] n2 = new ulong[p, 2];
            int i = 0;
            int c = 0;
            ulong v;
            ulong g1 ;
            ulong g2 = 0;
            for (i = 0; i < p; i++)
            {
                n2[i, 0] = 2;
                n2[i, 1] = 2;
            }
                for (i = 0; i < p; i++)
            {
                string[] rec = Console.ReadLine().Split();
                for (int j = 0; j < 2; j++)
                {
                    n[i, j] = ulong.Parse(rec[j]);
                }
            }
            // c1 = Math.Sqrt(n[0, 0]);
            for (c = 0; c < p; c++)
            {
                g1 = Convert.ToUInt64(Math.Sqrt(n[c, 0]));
                g2 = Convert.ToUInt64(Math.Sqrt(n[c, 0]));
                v = n[c, 0] / 2;
                if (g1 % 2 == 0)
                {
                    g1++;
                    g2++;
                }
                if (n[c, 0] % 2 == 0)
                {
                    v = v + 1;
                }
                for (ulong t = 1; t < Math.Sqrt(n[c, 0]); t = t + 2)
                {

                  //  Console.WriteLine("br 1 " + t + " br 2 " + v + " br3 " +g1+ " br4 "+g2);
                    if (n[c, 0] % t == 0)
                    {
                        ulong k = n[c, 0] / t ^ t;
                        if (k == n[c, 1])
                        {
                            n2[c, 0] = n[c, 0] / t;
                            n2[c, 1] = t;
                            break;
                        }


                    }
                    if (n[c, 0] % v == 0)
                    {
                        ulong k = n[c, 0] / v ^ v;
                        if (k == n[c, 1])
                        {
                            n2[c, 0] = n[c, 0] / v;
                            n2[c, 1] = v;
                            break;
                        }
                    }

                    if (n[c, 0] % g1 == 0)
                    {
                        ulong k = n[c, 0] / g1 ^ g1;
                        if (k == n[c, 1])
                        {
                            n2[c, 0] = n[c, 0] / g1;
                            n2[c, 1] = g1;
                            break;
                        }


                    }
                    if (n[c, 0] % g2 == 0)
                    {
                        ulong k = n[c, 0] / g2 ^ g2;
                        if (k == n[c, 1])
                        {
                            n2[c, 0] = n[c, 0] / g2;
                            n2[c, 1] = g2;
                            break;
                        }


                    }
                    g2 = g2 - 2;
                    g1 = g1 + 2;
                    v = v - 2;
                }
            } 
                for (int y = 0; y < p; y++)
                {
                    Console.WriteLine();
                    for (int j = 0; j < 2; j++)
                    {
                    if (n2[y, j] != 2 )
                    {
                        Console.Write(" " + n2[y, j]);
                    }
                    
                    }
                if(n[y,0]==2 || n[y, 1] == 2) { Console.Write(-1); }
                }
                Console.ReadLine();
            }
        }
    }