#C10966. Sort Strings by Length and Lexicographical Order

    ID: 40229 Type: Default 1000ms 256MiB

Sort Strings by Length and Lexicographical Order

Sort Strings by Length and Lexicographical Order

You are given \(T\) test cases. For each test case, you are provided with an integer \(N\) followed by \(N\) strings. Your task is to sort the list of strings according to the following rules:

  • First, sort the strings in ascending order by their lengths.
  • If two strings have the same length, sort them lexicographically in a case-insensitive manner. This means that for any two strings \(s_1\) and \(s_2\), if \(\text{toLowerCase}(s_1) < \text{toLowerCase}(s_2)\), then \(s_1\) is considered smaller.

Print the sorted strings for each test case on a new line. The sorting is stable with respect to the original order if the case-insensitive comparisons result in a tie.

inputFormat

The first line of input contains a single integer \(T\) denoting the number of test cases. Each test case begins with an integer \(N\) representing the number of strings, followed by a line containing \(N\) space-separated strings.

outputFormat

For each test case, output a single line containing the sorted strings separated by a single space.

## sample
2
3
Apple apple Banana
4
pear Peach PEAR peach
Apple apple Banana

pear PEAR Peach peach

</p>