def main(): N, M, K = map(int, input().split()) K %= M if N >= M - K: return 0 return K T = int(input()) for _ in range(T): print(main())