QOJ.ac

QOJ

Time Limit: 1.0 s Memory Limit: 256 MB Total points: 100 Hackable ✓

#18127. Hikoutei

Statistics

"For problems you don’t know how to solve, just submit something random. Who knows, maybe it will pass."

Given an $n \times m$ matrix of numbers, you may arbitrarily rearrange the numbers in each row so that the sum of the minimum values of all columns is maximized.

Formally, let the rearranged matrix be $A$. Maximize $\sum_{j=1}^m (\min_{i=1}^n A_{i,j})$.

You need to output this maximum value.

"More often than not, things going against our wishes is simply the norm in life."

Input

The first line of the input contains the number of test cases $T$ ($1 \leq T \leq 10^5$).

For each test case, the first line contains two positive integers $n, m$ ($1 \leq n, m \leq 1000$), representing the size of the matrix.

The next $n$ lines each contain $m$ integers, representing the numbers $A_{i,j}$ in the matrix ($0 \leq A_{i,j} \leq 10^9$).

It is guaranteed that the sum of $n \cdot m$ over all test cases does not exceed $10^6$.

Output

For each test case, output a single integer on one line representing the answer.

Examples

Input 1

3
1 1
5
2 2
1 4
2 5
3 3
1 2 1
2 2 1
1 1 2

Output 1

5
5
4

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.