import sys input = lambda: sys.stdin.readline().rstrip() # ----------------------- # def main(): n, m, k = map(int, input().split()) return k%m if k%m < m-n else 0 print('\n'.join(str(main()) for _ in range(int(input()))))