Report Recovery

No attempts yetTime limit3sMemory limit128 MB

Statement

At the end of the week, John asked Mary to send him an urgent sales report. In a hurry to leave for her holiday, Mary copy-pasted the sales sheet into an email, sent it, then turned off her phone and left for a place where she would be unreachable for two weeks.

When John opened the message, he discovered that every space had been stripped out. Fortunately, he remembered the exact shape of the report:

  • The first line is a header: the product codes P1 P2 ... PN followed by the word Totals. Products are numbered consecutively from 1 to N.
  • Each following line (except the last) reports one seller. It starts with the seller's name (a single word of letters), then lists, in order, the number of units that seller sold of each of the N products, and ends with that seller's row total (the sum of those N numbers).
  • The last line starts with the marker TP, followed by the total sold of each product (the column sums over all sellers), and finally the grand total (the sum of those column totals).

All quantities are non-negative integers. A quantity of zero is written as a single 0, and a positive quantity has no leading zeros. No seller's name begins with the letters TP.

Because the spaces are gone, more than one report may be consistent with the same run of digits. Help John rebuild the report; when several reconstructions are possible, output the lexicographically smallest one (defined in Output).

Input

The first line contains an integer C, the number of reports. Each report is then given, with all spaces removed, on consecutive lines: a header line, one line per seller, and finally the TP line.

Constraints:

  • $1 \le N \le 5$ (products per report);
  • at most 4 sellers per report;
  • each seller name has 1 to 10 letters (uppercase or lowercase);
  • each seller sold fewer than 1000 units of each product;
  • no seller name begins with TP.

Output

For each report, print the reconstructed report, one line per original line, with items separated by a single space and no trailing space. Do not print blank lines between reports.

If several reconstructions are consistent with the input, print the lexicographically smallest one. To compare two candidate reports, list all of their integers in reading order — for each seller row its N quantities followed by its row total, taken in the given seller order, then the totals row's column sums followed by the grand total — and compare these two integer sequences element by element; the smaller report is the one with the smaller value at the first position where they differ.