You learned to combine multiple string operations: checking length, accessing specific characters by index, and concatenating strings with numbers. The "read n, then loop n times" pattern is one of the most common in competitive programming.
You'll see it in nearly every contest. Get comfortable with it. Always check if a transformation is needed before applying it. Here, short words stay unchanged. Handle the simple case first (print as-is), then the complex case (abbreviate).
This makes your code clearer and less error-prone.