using System; using System.Collections.Generic; using System.Linq; class Program { static void Main(string[] args) { var T = int.Parse(Console.ReadLine()); for (int h = 1; h <= T; h++) { var input = Console.ReadLine().Split().Select(int.Parse).ToArray(); var N = input[0]; var M = input[1]; var K = input[2]; var prev = K % M; var current = 0; for (int i = 1; i <= N; i++) { current = prev % (M - i); prev = current; } Console.WriteLine(current); } } }