You are given two permutations$$$^{\text{∗}}$$$ and must compute the edit distance between them using only the following edits:
The edit distance between two permutations $$$p$$$ and $$$q$$$ is the minimum possible number of edits it takes to turn $$$p$$$ into $$$q$$$ or vice versa. It can be shown that, given the edits above, it does not matter which permutation you start with.
$$$^{\text{∗}}$$$A permutation of length $$$n$$$ is an array consisting of $$$n$$$ distinct integers from $$$1$$$ to $$$n$$$ in arbitrary order. For example, $$$[2,3,1,5,4]$$$ is a permutation, but $$$[1,2,2]$$$ is not a permutation ($$$2$$$ appears twice in the array), and $$$[1,3,4]$$$ is also not a permutation ($$$n=3$$$ but there is $$$4$$$ in the array).
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 2 \cdot 10^5$$$). The description of the test cases follows.
The first line of each test case contains two integers $$$n$$$ and $$$m$$$ ($$$1\leq n,\,m\leq 2\cdot10^5$$$) — the lengths of the permutations.
The second line of each test case contains $$$n$$$ integers $$$p_1,\,p_2,\,\ldots,\,p_n$$$ ($$$1\leq p_i\leq n$$$) — the permutation $$$p$$$.
The last line of each test case contains $$$m$$$ integers $$$q_1,\,q_2,\,\ldots,\,q_m$$$ ($$$1\leq q_i\leq m$$$) — the permutation $$$q$$$.
It is guaranteed that the sum of $$$\max(n,\,m)$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.
For each test case, output a single integer — the minimum number of valid edits to transform $$$p$$$ into $$$q$$$.
34 51 2 3 41 5 2 3 43 31 2 33 2 11 111
140
In the first test case, inserting 5 into $$$p$$$ in the second position will result in $$$q$$$.
In the second test case, first delete $$$3$$$ and $$$2$$$ from the end of $$$p$$$. Then insert $$$2$$$ into the beginning, and after that insert $$$3$$$ into the beginning as well. This will result in $$$q$$$, and it can be shown that this is a minimal solution.
In the third test case, the permutations are already equal.