F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

Express Mail Taking

Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/Others)
Total Submission(s): 2929    Accepted Submission(s): 1004


Problem Description
Besides on the traditional classes,Baby Volcano also needs to learn how to take the express mails.

Usually express mails are stored in cabinets. In Baby Volcano's school,there are $n$ cabinets in a row,numbered by $1$ to $n$. The distance between two adjacent cabinets is $1$, and the entrance is at the cabinet $1$. Among all $n$ cabinets,the one numbered $k$ is special and it is used to enter the code and open the cabinet door.

Baby Volcano has $m$ express mails to take,the $i$-th is in the cabinet $a_i$.
Two express mails will not be stored in the same cabinet. Also there is no express mail in the cabinet $k$.

To prevent expresses from being stolen, Baby Volcano have to take these express mails one by one, starting at the entrance. Generally, if he wants to take the express mail $i$, he have to walk to cabinet $k$ first to enter the code, and then walks to cabinet $a_i$. After taking the last one,he walks to the entrance.

There are so many express mails to take, so Baby Volcano wants to find a taking order which minimize the distance he walks.
 

Input
The first line contains one integer $T(1 \le T \le 100)$,the number of testcases.

For each test cases,the first line contains three integer $n,m,k(1 \le k \le n \le 10^9,1 \le m < \min(n,10^6))$

The next line contains $m$ integer,the $i$-th stand for $a_i(1 \le a_i \le n,a_i \neq k)$.

The input guarantees that $\sum m \le 2 \times 10^6$

**Note:Because of the large input,it is prefered to use scanf instead of cin.**
 

Output
For each test case,Output a single line contains one integer,representing for the minimal walking distance.
 

Sample Input
2 10 2 5 6 7 10 2 5 3 4
 

Sample Output
14 10
 

Source
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2024 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2024-05-08 13:36:44, Gzip enabled