#C10000. Case-Insensitive Word Sorting

    ID: 39158 Type: Default 1000ms 256MiB

Case-Insensitive Word Sorting

Case-Insensitive Word Sorting

In this problem, you are given a series of test cases. For each test case, you are provided with an integer ( n ) followed by ( n ) words. Your task is to sort the words in each test case in a case-insensitive manner. In other words, you should compare words by their lowercase forms while preserving the original case in the final output. Note that if two words are equal ignoring the case, their relative order should remain the same as in the input (i.e., the sort is stable).

For example, if you are given the words "Banana", "apple", "Grape", the output should be "apple Banana Grape" since "apple" comes first when compared in lowercase, followed by "Banana" and "Grape". Similarly, for words with the same letters in different cases, the original order is kept.

The sorting criterion can be mathematically expressed as: given two words ( a ) and ( b ), compare ( \text{lower}(a) ) and ( \text{lower}(b) ).

inputFormat

The input is read from standard input (stdin). The first line of input contains a single integer ( T ) representing the number of test cases. The following lines describe the test cases. For each test case, there are two lines:

  1. The first line contains an integer ( n ), the number of words.
  2. The second line contains ( n ) words separated by spaces.

outputFormat

For each test case, output a single line to standard output (stdout) containing the sorted words separated by a single space. The order of outputs must correspond to the order of test cases.## sample

1
3
Banana apple Grape
apple Banana Grape

</p>