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 remainder = K % M; if (M - N <= remainder) Console.WriteLine(0); else Console.WriteLine(remainder); } } }