There are $L$ bus stops uniformly distributed along a highway, numbered from $1$ to $L$. Initially, there are $n$ passengers waiting for the bus. The $i$-th passenger is waiting at stop $s_i$ and their destination is stop $t_i$. It is guaranteed that $s_i \neq t_i$.
There is exactly one bus operating on this highway, initially located at stop $p$.
If the bus is at stop $i$, it can move to stop $(i-1)$ or $(i+1)$ in one unit of time, provided the stop number is within $[1, L]$. At the initial stop or after moving from one stop to another, the bus will open its doors to pick up all passengers waiting at that stop and drop off all passengers on the bus whose destination is that stop.
Assume the bus has infinite capacity, the bus's movement between stops can be chosen arbitrarily, and passengers boarding or alighting do not consume time. You need to find the minimum number of units of time required for the bus to transport all $n$ passengers to their destinations.
Since no one knows where the bus is initially parked, you also need to solve $q$ queries. Each query provides a different $p$, while the passenger information remains the same. You need to find the answer to the above problem for each query.
Input
The data is read from standard input.
The first line contains a positive integer $id$, representing the subtask number.
- The first line contains three integers $L, n, q$, representing the number of bus stops, the number of passengers, and the number of queries.
- The next $n$ lines each contain two integers $s_i, t_i$, describing a passenger.
- The next line contains $q$ integers $p_1, p_2, \dots, p_q$, describing the value of $p$ for each query.
Output
Output to standard output.
For each test case, output a line containing $q$ integers $a_1, a_2, \dots, a_q$, representing the answers to each query in order.
Examples
Input
1
20 2 3
3 5
10 12
2 6 9
Output
10 12 14
Note
- In the first query, $p = 2$. The optimal way for the bus to move is to continuously increment the stop number, taking ten units of time to reach $12$.
- In the second query, $p = 6$. The optimal way for the bus to move is to first spend three units of time to reach $3$, then spend nine units of time to reach $12$.
- In the third query, $p = 9$. The optimal way for the bus to move is to first spend three units of time to reach $12$, then spend nine units of time to reach $3$, and finally spend two units of time to reach $5$.
Examples
Input
1
10 10 10
7 3
6 5
8 3
10 8
7 1
4 7
7 9
6 2
1 9
10 1
9 2 10 3 1 6 8 4 5 7
Output
18 19 17 20 18 21 19 21 22 20
Subtasks
For all test data:
- $1 \le L \le 10^{16}$, $1 \le n, q \le 10^{6}$;
- $\forall 1 \le i \le n, 1 \le s_i, t_i \le L, s_i \neq t_i$;
- $1 \le p_1, p_2, \dots, p_q \le L$;
- $\forall 1 \le i \le n, 1 \le j \le q, s_i \neq p_j, t_i \neq p_j$.
| Subtask ID | Score | $n,q \le$ | Special Property |
|---|---|---|---|
| 1 | 13 | $10$ | A |
| 2 | 14 | $50$ | None |
| 3 | 8 | $3,000$ | B |
| 4 | 12 | None | |
| 5 | 13 | $10^{6}$ | B |
| 6 | 16 | C | |
| 7 | 24 | None |
Special Property A: $L \le 10$.
Special Property B: $\forall 1 \le i \le n, 1 \le j \le q, p_j < s_i$.
Special Property C: $\forall 1 \le i \le n, 1 \le j \le q, p_j \not\in [\min(s_i,t_i), \max(s_i,t_i)]$.