CF1976B.Increase/Decrease/Copy

传统题 时间 2000 ms 内存 256 MiB 5 尝试 1 已通过 1 标签

Increase/Decrease/Copy

You are given two integer arrays: array aa of length nn and array bb of length n+1n+1.

You can perform the following operations any number of times in any order:

  • choose any element of the array aa and increase it by 11;
  • choose any element of the array aa and decrease it by 11;
  • choose any element of the array aa, copy it and append the copy to the end of the array aa.

Your task is to calculate the minimum number of aforementioned operations (possibly zero) required to transform the array aa into the array bb. It can be shown that under the constraints of the problem, it is always possible.

Input

The first line contains a single integer tt (1t1041 \le t \le 10^4) — the number of test cases.

Each test case consists of three lines:

  • the first line contains a single integer nn (1n21051 \le n \le 2 \cdot 10^5);
  • the second line contains nn integers a1,a2,,ana_1, a_2, \dots, a_n (1ai1091 \le a_i \le 10^9);
  • the third line contains n+1n + 1 integers b1,b2,,bn+1b_1, b_2, \dots, b_{n + 1} (1bi1091 \le b_i \le 10^9).

Additional constraint on the input: the sum of nn over all test cases doesn't exceed 21052 \cdot 10^5.

Output

For each test case, print a single integer — the minimum number of operations (possibly zero) required to transform the array aa into the array bb.

Note

In the first example, you can transform aa into bb as follows: $[2] \rightarrow [2, 2] \rightarrow [1, 2] \rightarrow [1, 3]$.

Samples

3
1
2
1 3
2
3 3
3 3 3
4
4 2 1 2
2 1 5 2 3
3
1
8

在线编程 IDE

建议全屏模式获得最佳体验