TUPLEDIV - Tuple Division

You are given N tuples with M dimensions. You need to choose some tuples and divide them into M groups. Each tuple can be used for only once and the size of the ith group is Ci. We define the score of the ith group is the sum of value in the ith dimension of the tuples in the ith group. Your target is to firstly maximize the score of 1st group, then maximize the score 2nd group and so on. 

Input

The first line of the input contains an integer T (T ≤ 50), indicating the number of cases. Each case begins with two integer N (1 ≤ N ≤ 10000) and M (1 ≤ M ≤ 10), the number of tuples and the number of groups. Then there is one line contain M integers. The ith integer Ci (Ci ≥ 0, sigma Ci ≤ N) represents the size of the ith group. Then N lines with M integers follow. Each of them describes a tuple. The jth integer on the ith line Tij (0 ≤ Tij ≤ 10000) denotes the value of the jth dimension of the ith tuple.

Output

For each test case, print one line with M score of some optimal division.

Example

Input:
2
4 2
2 1
3 2
2 1
2 2
1 1
4 3
1 1 2
8 7 1
8 7 2
8 7 4
8 2 3

Output:
5 2
8 7 7

Hint

In case 2, we can divide the group like:

  • Group 1: (8, 7, 2)  score = 8
  • Group 2: (8, 7, 1)  score = 7
  • Group 3: (8, 7, 4), (8, 2, 3) score = 4 + 3 = 7

Added by:3xian
Date:2011-10-18
Time limit:1s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All
Resource:code6

hide comments
2020-05-16 20:43:39
Are there any limits on sum of N in one test?
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.