$/=$%=<>; $_=<>; s/\./!/; ($a,$b)=('!',A..Z,a..j)[$i,$i+1], s/\.(.{$%})?!|!(.{$%})?\./!$1$2!/s|| s/$a(.{$%})?#/$a$1$b/s|s/#(.{$%})?$a/$b$1$a/s|| $i++until/\w(.{$%})?\.|\.(.{$%})?\w/s; print$i+1