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

namespace ConsoleApp1
{
    internal class Program
    {
        static void Main(string[] args)
        {
            int t =Convert.ToInt32(Console.ReadLine());
            for (int i = 0; i < t; i++)
            {
                string[]unos = Console.ReadLine().Split(' ');
                int n = Convert.ToInt32(unos[0]);   
                int m = Convert.ToInt32(unos[1]);
                Dictionary<int, List<int>>vrednostvrste=new Dictionary<int,List<int> >();   
                if (m != n) Console.WriteLine(-1);
                else 
                {
                    bool ok = true;
                    int[,] matrica = new int[n, m];
                    for (int k = 1; k <= n; k++) 
                    {
                        if (n % k != 0) 
                        {
                            int pomoc=n%k;
                            if (!vrednostvrste.ContainsKey(pomoc)) vrednostvrste[pomoc].Add(k);
                        }
                    }
                   
                    
                    
                }
            }
        }
    }
}