#K79362. Ancient Sorting of Books

    ID: 35292 Type: Default 1000ms 256MiB

Ancient Sorting of Books

Ancient Sorting of Books

An ancient library holds a collection of mystical books, each containing forgotten knowledge. The chief librarian has mastered an ancient method to sort these books based on the total information they contain. The total information of a book is defined as the sum of the values written on each of its pages. As an understudy of the chief librarian, your task is to help sort these books in increasing order of their total information. If two books have the same total information, maintain their original order in the input.

Input Format: The input begins with an integer T representing the number of test cases. For each test case, the first line contains an integer n representing the number of books. The next line contains n space-separated integers indicating the number of pages in each book. This is followed by n lines, where the i-th line contains space-separated integers corresponding to the information on each page of the i-th book.

Constraints:

  • $1 \le T \le 10$
  • $1 \le n \le 100$
  • $1 \le pages_i \le 100$
  • $1 \le value \le 1000$ for each page

Output Format: For each test case, output a single line containing the indices of the books sorted in increasing order of total information. Indices start from 0. In the case of ties in total information, the order from the input should be preserved.

Example:

Input:
2
3
3 2 4
1 2 3
4 5
3 3 3 3
2
5 2
6 6 6 6 6
1 1

Output: 0 1 2 1 0

</p>

inputFormat

The input is read from standard input and follows this format:

  1. The first line contains an integer T, the number of test cases.
  2. Each test case begins with an integer n, the number of books.
  3. The next line contains n space-separated integers, where the i-th integer represents the number of pages in the i-th book.
  4. This is followed by n lines. The i-th of these lines contains as many space-separated integers as pages in the i-th book, representing the information on each page.

Note: All input is provided via standard input (stdin).

outputFormat

For each test case, output a single line to standard output (stdout) containing the indices of the books sorted by increasing order of their total information. Indices are space-separated. In case of ties, maintain the original order as provided in the input.

## sample
2
3
3 2 4
1 2 3
4 5
3 3 3 3
2
5 2
6 6 6 6 6
1 1
0 1 2

1 0

</p>