t=int(input()) def solve(n): for i in range(1,10**5+1): if int(str(n)+str(i))%(n+i)==0: print(i) break for _ in range(t): solve(int(input()))