def main(): t = int(input()) for _ in range(t): n, m, k = map(int, input().split()) a0 = k % m if a0 < m - n: print(a0) else: print(0) if __name__ == "__main__": main()