{"trustable":true,"prependHtml":"\u003cscript\u003e window.katexOptions \u003d { disable: true }; \u003c/script\u003e\n\u003cscript type\u003d\"text/x-mathjax-config\"\u003e\n MathJax.Hub.Config({\n tex2jax: {\n inlineMath: [[\u0027$$$\u0027,\u0027$$$\u0027], [\u0027$\u0027,\u0027$\u0027]],\n displayMath: [[\u0027$$$$$$\u0027,\u0027$$$$$$\u0027], [\u0027$$\u0027,\u0027$$\u0027]]\n }\n });\n\u003c/script\u003e\n\u003cscript async src\u003d\"https://mathjax.codeforces.org/MathJax.js?config\u003dTeX-AMS-MML_HTMLorMML\" type\u003d\"text/javascript\"\u003e\u003c/script\u003e","sections":[{"title":"","value":{"format":"HTML","content":"\u003cdiv class\u003d\"panel_content\"\u003eIn 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.\u003cbr\u003e\u003cbr\u003e\u003ccenter\u003e\u003cbr\u003e\u003cimg style\u003d\"max-width:100%;\" src\u003d\"CDN_BASE_URL/cd61fa555c59b799a4bc764efcd54450?v\u003d1714408165\"\u003e\u003cbr\u003ePicture from Wikimedia Commons\u003cbr\u003e\u003c/center\u003e \u003cbr\u003e\u003cbr\u003eTwo 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.\u003cbr\u003e\u003cbr\u003eLittle 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\u0027t 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.\u003cbr\u003e\u003cbr\u003ePlease write a program to help Little Q find the best way costing the minimum time.\u003c/div\u003e"}},{"title":"Input","value":{"format":"HTML","content":"The first line of the input contains an integer $T(1\\leq T\\leq15)$, denoting the number of test cases.\u003cbr\u003e\u003cbr\u003eIn 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$.\u003cbr\u003e\u003cbr\u003eIn 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.\u003cbr\u003e\u003cbr\u003eThen 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."}},{"title":"Output","value":{"format":"HTML","content":"For each test case, print a single line containing an integer, denoting the minimum time to check all people."}},{"title":"Sample","value":{"format":"HTML","content":"\u003ctable class\u003d\u0027vjudge_sample\u0027\u003e\n\u003cthead\u003e\n \u003ctr\u003e\n \u003cth\u003eInput\u003c/th\u003e\n \u003cth\u003eOutput\u003c/th\u003e\n \u003c/tr\u003e\n\u003c/thead\u003e\n\u003ctbody\u003e\n \u003ctr\u003e\n \u003ctd\u003e\u003cpre\u003e1\r\n4 2\r\n2 3 1 4\r\n1 2 4 3\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e7\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n"}},{"title":"Hint","value":{"format":"HTML","content":"\u003cbr\u003eTime 1 : Check A_1.\u003cbr\u003eTime 2 : Check A_2.\u003cbr\u003eTime 3 : Check A_3.\u003cbr\u003eTime 4 : Check A_4 and B_1.\u003cbr\u003eTime 5 : Check B_2.\u003cbr\u003eTime 6 : Check B_3.\u003cbr\u003eTime 7 : Check B_4.\u003cbr\u003e"}}]}