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