The country of Siruseri has A∗B$A*B$ districts. You want to create A$A$ states from these districts, such that each state has exactly B$B$ districts, and each district is part of exactly one state. You don't care about the geographical location of the districts. You can pick any B$B$ districts and make it into a state.
There are only two parties contesting in the coming elections: P1$P_1$ and P2$P_2$. You know the number of votes that each party receives in each district. In the i-th district, P1$P_1$ gets ci$c_i$ votes and P2$P_2$ gets di$d_i$ votes. You are guaranteed that all these 2∗A∗B$2*A*B$ integers (the number of votes received by each party in the districts) are distinct. Also, both A$A$ and B$B$ are odd. 
Suppose you have chosen which districts belong to which states, then, to find out who wins any particular state, they follow a weird rule: Suppose the number of votes that P1$P_1$ gets in the B$B$ districts of a particular state are x1,x2,…,xB$x_1, x_2, \ldots, x_B$, and the number of votes that P2$P_2$ gets in the B$B$ districts of this state are y1,y2,…,yB$y_1, y_2, \ldots, y_B$. Then among all these 2∗B$2*B$ numbers, the largest number is chosen (note that we are guaranteed of an unique largest number). If that number is some xi$x_i$, then P1$P_1$ wins this state. If the largest number is some yj$y_j$, then P2$P_2$ wins this state.
You secretly support the party P1$P_1$, and hence you want to assign the districts to states, in such a way, that the number of states won by P1$P_1$ is maximized. Find this maximum number of states that P1$P_1$ can win.
Note that ci$c_i$ and di$d_i$ will always remain associated with the i-th district. If the i-th district gets assigned to a particular state, then both ci$c_i$ and di$d_i$ will be considered when deciding who won that state.
-----Input:-----
- The first line of the input contains a single integer, T$T$, the number of testcases. The description of each testcase follows.
- The first line of each testcase contains two integers, A$A$ and B$B$.
- The second line of each testcase contains A∗B$A*B$ integers: c1,c2,…,cA∗B$c_1, c_2, \ldots, c_{A*B}$, the number of votes won by P1$P_1$ in the districts.
- The third line of each testcase contains A∗B$A*B$ integers: d1,d2,…,dA∗B$d_1, d_2, \ldots, d_{A*B}$, the number of votes won by P2$P_2$ in the districts.
-----Output:-----
For each testcase output a single line which contains the maximum number of states that P1$P_1$ can win.
-----Constraints:-----
- 1≤T≤5$1 \leq T \leq 5$
- 1≤A,B$1 \leq A, B$
- A∗B≤105$A*B \leq 10^5$
- A$A$, B$B$ are odd
- 1≤ci,di≤109$1 \leq c_i, d_i \leq 10^9$
- All the ci$c_i$ and di$d_i$ will be distinct.
-----Sample Input:-----
3
1 3
4 2 9
5 6 7
1 3
4 2 9
5 10 7
3 3
7 14 11 4 15 5 20 1 17
2 13 16 9 19 6 12 8 10
-----Sample Output:-----
1
0
3
-----Explanation:-----
Testcase 1: Since you have to form only 1 state, there is no choice, but to put all the 3 districts in that same state. Now to figure out who wins that single state, we take the maximum among {4, 2, 9, 5, 6, 7}. The maximum is 9, and that belongs to P1$P_1$. Hence P1$P_1$ wins this state. And because they have won 1 state, the answer is 1.
Testcase 2: Similarly, there is no choice here. To figure out who wins that single state, we take the maximum among {4, 2, 9, 5, 10, 7}. The maximum is 10, and that belongs to P2$P_2$. Hence P2$P_2$ wins this state. And because P1$P_1$ have won no states, the answer is 0.
Testcase 3: We need to make three states with three districts each. Suppose we that the 3rd, 5th and 7th districts and form a state, the votes in them would be {11, 16, 15, 19, 20, 12}. The max among these is 20, and that belongs to P1$P_1$. Hence P1$P_1$ would win this state. 
Similarly, suppose we make the second state with the 2nd, 4th and 8th districts, the votes in them would be {14, 13, 4, 9, 1, 8}. The max among these is 14, and that belongs to P1$P_1$. Hence P1$P_1$ would win this state. 
The remaining three districts: 1st, 6th and 9th districts form the third state. The votes in them would be {7, 2, 5, 6, 17, 10}. The max among these is 17, and that belongs to P1$P_1$. Hence P1$P_1$ would win this state. 
In this situation, P1$P_1$ wins three states. You obviously cannot do any better. Hence the answer is 3.
# cook your dish here
# cook your dish here
for i in range(int(input())):
    a,b=[int(i) for i in input().split()]
    l1=[int(i) for i in input().split()]
    l2=[int(i) for i in input().split()]
    l=[]
    for i in range(a*b):
     if(l1[i]>l2[i]):
      l.append([l1[i],1])
     else:
      l.append([l2[i],2])
    l.sort()
    arr=[]
    for i in range(a*b):
     if(l[i][1]==1):
      arr.append(i+1)
    j=1
    ans=0
    for i in range(len(arr)):
     if(arr[i]>=j*b):
      ans+=1 
      j+=1 
    print(ans)
  

# cook your dish here
# cook your dish here
for i in range(int(input())):
    a,b=[int(i) for i in input().split()]
    l1=[int(i) for i in input().split()]
    l2=[int(i) for i in input().split()]
    l=[]
    for i in range(a*b):
     if(l1[i]>l2[i]):
      l.append([l1[i],1])
     else:
      l.append([l2[i],2])
    l.sort()
    arr=[]
    for i in range(a*b):
     if(l[i][1]==1):
      arr.append(i+1)
    j=1
    ans=0
    for i in range(len(arr)):
     if(arr[i]>=j*b):
      ans+=1 
      j+=1 
    print(ans)
  
