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