My code is passing for all test case but not in one and i can’t find my mistake…please help me…

here is the code

t=int(input())

while(t>0):

n=input()

i=0

while(n[i]==‘0’):

i+=1

n=n[i:]

k=len(n)

a=n[0]+‘9’*(k-1)
if(n==a):
print(a)
else:
if(n[0]==‘1’):
i=1
while(i<k and n[i]==‘0’):
i+=1
if(i>=k-1):
print(n)
else:
a=n[:i+1]+‘9’*(k-i-1)

if(n==a):

print(a)

else:

a=n[:i]+str(int(n[i])-1)+‘9’

*(k-i-1)*

print(a)

else:

a=str(int(n[0])-1)+‘9’(k-1)

print(a)

else:

a=str(int(n[0])-1)+‘9’

print(a)

t=t-1