This is an easier version of the next problem. The difference is only in constraints.

You are given a rectangular n × m matrix a. In one move you can choose any column and cyclically shift elements in this column. You can perform this operation as many times as you want (possibly zero). You can perform this operation to a column multiple times.

After you are done with cyclical shifts, you compute for every row the maximal value in it. Suppose that for i-th row it is equal r_i. What is the maximal possible value of r_1+r_2+…+r_n?

Input

The first line contains an integer t (1 ≤ t ≤ 40), the number of test cases in the input.

The first line of each test case contains integers n and m (1 ≤ n ≤ 4, 1 ≤ m ≤ 100) — the number of rows and the number of columns in the given matrix a. 

Each of the following n lines contains m integers, the elements of a (1 ≤ a_{i, j} ≤ 10^5).

Output

Print t integers: answers for all test cases in the order they are given in the input.

Example

Input


2
2 3
2 5 7
4 2 4
3 6
4 1 5 2 10 4
8 6 6 4 9 10
5 4 9 5 8 7


Output


12
29

Note

In the first test case, you can shift the third column down by one, this way there will be r_1 = 5 and r_2 = 7.

In the second case you can don't rotate anything at all, this way there will be r_1 = r_2 = 10 and r_3 = 9.
import sys,os,math
from collections import Counter, defaultdict
import bisect
from sys import stdin, stdout
from itertools import repeat


# sys.stdin = open('input')
# n, k = map(int, raw_input().split())
# da = map(int, raw_input().split())
# db = map(int, raw_input().split())

def ckpos(i, j):
    if abs(i-j)==1 or abs(i-j)==2:
        return abs(i-j)
    else:
        return 1
da = []
so = []
s5, s6 = 0, 0
def solve():
    n, m = map(int, raw_input().split())
    global da,so,s5,s6
    da = []
    for i in range(n):
        da.append(map(int, raw_input().split()))
    so = []
    for i in range(n):
        for j in range(m):
            so.append((da[i][j], i ,j))
    so.sort(reverse=True)
    ans = 0
    for i in range(n):
        ans += so[i][0]
    if n < 4:
        return ans

    s6 = 0 if len(so) <5 else so[5][0]
    s5 = 0 if len(so) <5 else so[4]
    # print s5
    s4 = so[3]
    so = so[:4]
    so.sort(key = lambda tp: tp[2])
    # print so
    if so[0][2] == so[1][2] and so[2][2] == so[3][2] and so[0][2]!=so[2][2] and ckpos(so[0][1], so[1][1]) != ckpos(so[2][1], so[3][1]):
        ans -= s4[0]
        # print '????'
        for iidd, ssao in enumerate(so):
            if ssao[2] == s4[2] and ssao[1]!=s4[1]:
                iidx = iidd
                break
        # print s5[2] , s4[2]
        if s5[2] == s4[2] and ckpos(s5[1], so[iidx][1])==1 and ckpos(s4[1], so[iidx][1])==1:
            # print '????'
            if iidx <=1:
                if ckpos(s5[1], so[iidx][1]) != ckpos(so[2][1], so[3][1]):
                    return max(ans + s6, ans+s4[0]+s5[0] - min(so[2][0], so[3][0]))
                else:
                    return ans + s5[0]
            else:
                if ckpos(s5[1], so[iidx][1]) != ckpos(so[0][1], so[1][1]):
                    return max(ans + s6, ans+s4[0]+s5[0] - min(so[2][0], so[3][0]))
                else:
                    return ans + s5[0]
        else:
            return ans + s5[0]
    else:
        return ans

def main():
    q = map(int, raw_input().split())[0]
    for qq in range(q):
        ans = solve()
        # if ans == 230240:
        #     print so,s5,s6
        print ans

main()
#
# print 76756 + 55879 + 71077 + 47849
# print 251561
