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(a_0) else: print(lists[i]%i)