program main implicit none integer::N,i,j,first,last character*100001::S="" character*10::num='0123456789' read *,N do i=1,N read '(a)',S last = scan(S,num,.true.) if(last.eq.0) then print '(a)', TRIM(S) cycle end if first= verify(S(1:last),num,.true.) if(S(first+1:last).eq.REPEAT('9',last-first)) then do j=LEN_TRIM(S), last, -1 S(j+1:j+1) = S(j:j) end do S(first+1:first+1) = '1' S(first+2:last+1) = REPEAT('0',last-first) else first = verify(S(1:last),'9',.true.) S(first:first)=ACHAR(ICHAR(S(first:first))+1) if(first.ne.last) then S(first+1:last)='0' end if end if print '(a)', TRIM(S) end do end program main