t = int(input()) for _ in range(t): n = int(input()) f = 1 while True: a = n + f b = int(str(n) + str(f)) if b % a == 0: print(f) break f += 1