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