T = int(input()) c = list(input() for _ in range(T)) for i in range(T): for M in range(1,10000000): A=int(c[i])+M B=int(c[i]+str(M)) if B%A == 0: print(M) break