i got correct answer during compiling but at the time of submission there occurs an error of time limit exceeded..could anyone help me?

i have mentioned my question link:

MY CODE:
def first(y):
a=list(str(y))
z=int(a[0])
return z
d=int(input())
x=list()
for i in range(d):
n=int(input())
m=20
j=1
i=3
b=10
if(n==2):
b=9
print(b)
continue
while(i!=n):
i=i+1
if((m-first(m)) < b < m):
j=j+1
b=b+j
m=m+10
else:
if(j==9):
b=b+j-1
j=1
else:
b=b+j
print(b)

Your code loops from 3 to n ( while(i!=n): i=i+1 ). n can be as large as 10^12. The time limit for the question is 2 seconds and in 1 second, codechef servers can do around 10^8 operations. Your code will take about 1000 seconds per test case. Obviously you’ll exceed the time limit.

Also you can just post a link to your submission instead of just writing you code here. You can find your submissions by clicking on “My submisions” on the problem page.

Try to find an algorithm which takes less time. If you can’t then comment here and I’ll post a thread discussing the solution.