#C6413. Largest Number Concatenation

    ID: 50171 Type: Default 1000ms 256MiB

Largest Number Concatenation

Largest Number Concatenation

You are given several test cases. In each test case, a list of non-negative integers is provided. Your task is to rearrange the numbers such that they form the largest possible numeric value when concatenated together.

The problem can be formulated as follows: for two numbers represented as strings x and y, define the custom comparator based on the condition \[ x+y > y+x \] If the above holds, x should come before y in the final ordering. Otherwise, y should precede x. Note that if the highest digit in the resulting string is 0, then the final answer should simply be 0.

Example: For the input list [10, 2, 9], the largest concatenated number is 9210.

inputFormat

The first line contains an integer T, the number of test cases. For each test case:

  • The first line contains an integer N, which is the number of integers in that test case.
  • The second line contains N space-separated non-negative integers.

All input is read from standard input (stdin).

outputFormat

For each test case, print the largest concatenated number on a new line. Output is written to standard output (stdout).

## sample
3
3
10 2 9
4
3 30 34 5
2
12 121
9210

534330 12121

</p>