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 = int.Parse(Console.ReadLine());
            for (int i = 0; i < t; i++)
            {
                string[] unos = Console.ReadLine().Split();
                int n = int.Parse(unos[0]);
                int m = int.Parse(unos[1]);
                if (m > n ||  (n / 2 != 0 && (m != 1)))
                {
                    Console.WriteLine(-1);

                }
                
            }
        }
    }
}