cho.sh
Notes
Loading...

Serial Numbers

Time limit

2s

Memory limit

128 MB

Problem

Dasom owns many guitars, and each guitar has a different serial number. To find the right guitar quickly, she wants to sort the guitars by serial number.

Every serial number consists only of uppercase English letters (A-Z) and digits (0-9).

Serial number A comes before serial number B by the following rules:

  1. If A and B have different lengths, the shorter serial number comes first.
  2. If they have the same length, compare the sum of the digit characters in each serial number. The serial number with the smaller sum comes first. Only digits are included in this sum.
  3. If the first two rules still do not decide the order, compare them lexicographically. In this comparison, digits come before letters.

Given the serial numbers, write a program that prints them in sorted order.

Input

The first line contains the number of guitars, N. N is at most 50.

Each of the next N lines contains one serial number. The length of each serial number is at most 50, and each serial number consists only of uppercase English letters or digits. No two serial numbers are the same.

Output

Print the sorted serial numbers, one per line, over N lines.