T = int(input()) for _ in range(T): N = int(input()) n = str(N) for k in range(1, 10 ** 5 + 1): if int(n + str(k)) % (N + k) == 0: print(k) break