CF2121A.Letter Home

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

Letter Home

You are given an array of distinct integers x1,x2,,xnx_1, x_2, \ldots, x_n and an integer ss.

Initially, you are at position pos=spos = s on the XX axis. In one step, you can perform exactly one of the following two actions:

  • Move from position pospos to position pos+1pos + 1.
  • Move from position pospos to position pos1pos - 1.

A sequence of steps will be considered successful if, during the entire journey, you visit each position xix_i on the XX axis at least once. Note that the initial position pos=spos = s is also considered visited.

Your task is to determine the minimum number of steps in any successful sequence of steps.

Input

Each test consists of multiple test cases. The first line contains a single integer tt (1t10001 \leq t \leq 1000) — the number of test cases. The description of the test cases follows.

The first line of each test case contains two integers nn and ss (1n101 \leq n \leq 10, 1s1001 \leq s \leq 100) — the number of positions to visit and the starting position.

The second line of each test case contains nn integers x1,x2,,xnx_1, x_2, \ldots, x_n (1xi1001 \leq x_i \leq 100). It is guaranteed that for all 1i<n1 \leq i \lt n, it holds that xi<xi+1x_i \lt x_{i + 1}.

Output

For each test case, output the minimum number of steps in any successful sequence of steps.

Note

In the first test case, no steps need to be taken, so the only visited position will be 11.

In the second test case, the following path can be taken: 212 \rightarrow 1. The number of steps is 11.

In the third test case, the following path can be taken: 121 \rightarrow 2. The number of steps is 11.

In the fifth test case, the following path can be taken: 21232 \rightarrow 1 \rightarrow 2 \rightarrow 3. The number of steps is 33.

Samples

12
1 1
1
1 2
1
1 1
2
2 1
2 3
2 2
1 3
2 3
1 2
3 1
1 2 3
3 2
1 3 4
3 3
1 2 3
4 3
1 2 3 10
5 5
1 2 3 6 7
6 6
1 2 3 9 10 11
0
1
1
2
3
2
2
4
2
11
8
15

在线编程 IDE

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