using System; using System.Linq; class M { static int[] Read() => Array.ConvertAll(Console.ReadLine().Split(), int.Parse); static (int, int) Read2() { var a = Read(); return (a[0], a[1]); } static void Main() => Console.WriteLine(string.Join("\n", new int[int.Parse(Console.ReadLine())].Select(_ => Solve()))); static object Solve() { var (a, b) = Read2(); return b * (b + 1) / 2 % 17; } }