#yuki_539 def f(ss): s=ss if not s[-1].isdigit(): return s if s.isdigit(): n1=int(s)+1 return '0'*(len(s)-len(str(n1)))+str(n1) s1='' while s[-1].isdigit(): s1+=s[-1] s=s[:-1] s2=str(int(s1[::-1])+1) if len(s1)>len(s2): s2='0'*(len(s1)-len(s2))+s2 return s+s2 n=int(raw_input()) for i in xrange(n): temp=raw_input() print f(temp)