using System;
class Program
{
    static void Main(string[] args)
    {
        int n = int.Parse(Console.ReadLine());
        long div = 0;
        long div2 = 0;
        string[] a;
        string[] twr = new string[n];
        string bintotal;
        long b, c ;
        bool fin = false;
        for (int i=0; i < n; i++)
        {
            fin = false;
            a = Console.ReadLine().Split(' ');
            b = long.Parse(a[0]);
            c = long.Parse(a[1]);
            for(long e = (long)Math.Sqrt(b)+((long)Math.Sqrt(b)+1)%2; e>= Math.Max(((long)Math.Sqrt(b) - c / 2) + ((long)Math.Sqrt(b) - (c / 2 - 1)) % 2, 1) && fin == false; e-=2)
            {
                if (b % e == 0)
                {
                    div = e;
                    div2 = b / e;
                    string bbin = Convert.ToString(div, 2);
                    string cbin = Convert.ToString(div2, 2);
                    char[] binchar = new char[Math.Max(bbin.Length, cbin.Length)];
                    if (bbin.Length > cbin.Length)
                    {
                        for (int j = 0; j < (bbin.Length - cbin.Length); j = 0)
                        {
                            cbin = "0" + cbin;
                        }
                    }
                    else if (bbin.Length < cbin.Length)
                    {
                        for (int j = 0; j < (cbin.Length - bbin.Length); j = 0)
                        {
                            bbin = "0" + bbin;
                        }
                    }
                    for (int j = 0; j < bbin.Length; j++)
                    {
                        if (bbin.Substring(j, 1).ToCharArray()[0] == cbin.Substring(j, 1).ToCharArray()[0])
                        {
                            binchar[j] = '0';
                        }
                        else
                        {
                            binchar[j] = '1';
                        }
                    }
                    bintotal = new string(binchar);
                    long finum = Convert.ToInt64(bintotal, 2);
                    if(finum == c)
                    {
                        twr[i] = (div + " " + div2);
                        fin = true;
                    }
                }
            }
            if (fin == false)
            {
                twr[i] = "-1" ;
            }
        }
        for(int i=0; i < n; i++)
        {
            Console.WriteLine(twr[i]);
        }
    }
}