T = int(input()) lists = [] for i in range(T): _ = i - 1 N,M,K = map(int, input().split()) if _ == 0: a_0 = K%M lists.append(a_0) print(a_0) else: print(lists[_]%_)