t = int(input()) for _ in range(t): a, b, c = map(int, input().split()) if c <= 40: print(a * pow(10, c) // b % 10) else: c2 = 0 while b % 2 == 0: b //= 2 c2 += 1 c5 = 0 while b % 5 == 0: b //= 5 c5 += 1 t = a * pow(2, c - c2, b) * pow(5, c - c5, b) % b l = [] for x in range(10): if (b * x + t) % 10 == 0: l.append(x) print(l[0])