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