#P1084. Fixed Point
Fixed Point
Description
Bobo has a sequence p1, p2, …, pn. Initially, pi = i holds.
One day, Bobo comes up with infinite operations. The operations are described by m pairs of integers (a1, b1), (a2, b2), …, (am, bm). The i-th operation is to reverse the elements between the a(i − 1) mod m + 1-th and the b(i − 1) mod m + 1-th. Note that a sequence q1, q2, …, qn becomes q1, …, qx − 1, qy, qy − 1, …, qx, qy + 1, …, qn after reversing the elements between the x-th and the y-th.
Bobo also has q questions k1, k2, …, kq. The i-th question is to ask the number of i satisfying pi = i if he executes only the first ki operations. Answer the questions!
- 1 ≤ n ≤ 105
- 1 ≤ m ≤ 10
- 1 ≤ q ≤ 105
- 1 ≤ ai ≤ bi ≤ n
- 1 ≤ ki ≤ 109
- The number of test cases does not exceed 5.
Input
The input consists of several test cases and is terminated by end-of-file.
The first line of each test case contains three integers n, m and q.
The i-th of the following m lines contains 2 integers ai and bi.
The i-th of the last q lines contains an integer ki.
Output
For each test case, print q integers which denote the answers.
5 1 2
2 4
1
2
5 2 1
1 3
3 5
1000000000
3
5
2
Hint
For the first sample, the sequence becomes 1, 4, 3, 2, 5 after the first operation, and becomes 1, 2, 3, 4, 5 after the second one. Thus, the answer are 3, 5 respectively.