""" Mの桁数をkとする B = N*(10^k) + M A = N+M B%A = Aは1ずつ Bは10^k ずつ増える N*(10^k-1) が N+M で割り切れる N*(99999) が N+M で割り切れる N*9 が N+M (1 <= M < 10) """ import sys from sys import stdin TT = int(stdin.readline()) for loop in range(TT): N = int(stdin.readline()) for bit in range(12): Q = (10**bit-1) * N flag = False for i in range(1,int(Q**0.5+10)): if Q % i == 0: x = i M = x - N if M > 0 and len(str(M)) == bit: flag = True break x = Q // i M = x - N if M > 0 and len(str(M)) == bit: flag = True break if flag: break print (M)