from sys import stdin pin=stdin.readline def main(): N=int(pin()) d=[0]*100 d[0]=1 a=1 b=9 for i in range(100): d[i]+=b-a+1 a*=10 b*=10 b+=9 for i in range(N): print(d[int(pin())-1]) return main()