#K65422. String Compression

    ID: 32194 Type: Default 1000ms 256MiB

String Compression

String Compression

This problem requires you to compress a given string by consolidating consecutive duplicate characters. For each sequence of consecutive identical characters, if the count is more than 1, it should be replaced with the character concatenated with the count. Otherwise, the character remains as is.

Formally, for a string \( s \), let \( s = c_1 c_2 \dots c_n \). The compressed string \( s' \) is built by grouping each maximal segment of equal characters \( c^{k} \) and replacing each group with \( c \) if \( k = 1 \) or \( c\,k \) (with \( k \) in base-10) if \( k > 1 \). The final answer is defined as follows:

\[ \text{answer} = \begin{cases} s' & \text{if }|s'| < |s|,\\ s & \text{otherwise.} \end{cases} \]

You are also required to process multiple test cases.

inputFormat

The program reads from standard input. The first line contains an integer \( T \) representing the number of test cases. The following \( T \) lines each contain a single string \( s \) consisting of lowercase letters.

outputFormat

For each test case, output the compressed string on a new line. The output should be written to standard output.

## sample
2
aaabccddd
abcd
a3bc2d3

abcd

</p>