Security Check

Time Limit: 6000/3000 MS (Java/Others)

Memory Limit: 524288/524288 K (Java/Others)

Description

In airport of Bytetown, there are two long queues waiting for security check. Checking a person needs one minute, and two queues can be checked at the same time. Picture from Wikimedia Commons

Two teams $A$ and $B$ are going to travel by plane. Each team has $n$ players, ranked from $1$ to $n$ according to their average performance. No two players in the same team share the same rank. Team $A$ is waiting in queue $1$ while team $B$ is waiting in queue $2$. Nobody else is waiting for security check.

Little Q is the policeman who manages two queues. Every time he can check one person from one queue, or check one each person from both queues at the same time. He can't change the order of the queue, because that will make someone unhappy. Besides, if two players $A_i$ and $B_j$ are being checked at the same time, satisfying $|A_i-B_j|\leq k$, they will make a lot of noise because their rank are almost the same. Little Q should never let that happen.

Please write a program to help Little Q find the best way costing the minimum time.

Input

The first line of the input contains an integer $T(1\leq T\leq15)$, denoting the number of test cases.

In each test case, there are $2$ integers $n,k(1\leq n\leq 60000,1\leq k\leq 10)$ in the first line, denoting the number of players in a team and the parameter $k$.

In the next line, there are $n$ distinct integers $A_1,A_2,...,A_n(1\leq A_i\leq n)$, denoting the queue $1$ from front to rear.

Then in the next line, there are $n$ distinct integers $B_1,B_2,...,B_n(1\leq B_i\leq n)$, denoting the queue $2$ from front to rear.

Output

For each test case, print a single line containing an integer, denoting the minimum time to check all people.

Sample Input

1 4 2 2 3 1 4 1 2 4 3

Sample Output

7
Hint
Time 1 : Check A_1. Time 2 : Check A_2. Time 3 : Check A_3. Time 4 : Check A_4 and B_1. Time 5 : Check B_2. Time 6 : Check B_3. Time 7 : Check B_4.

liuyiding

Source

2017 Multi-University Training Contest - Te