You are inside a boss arena. The arena consists of tiles numbered from $$$1$$$ to $$$n$$$. You spawned at tile $$$s$$$ and your goal is to survive this boss for $$$m$$$ seconds, but there is a catch.
For each second, the boss will shoot a lazer that hit exactly one segment of the arena. If you stand inside said segment when the boss shoots the lazer, you lose the game. More formally, at the $$$i$$$-th second, the boss will shoot a lazer that hit the segment $$$[l_i,r_i]$$$ where $$$1 \leq l_i \leq r_i \leq n$$$. If you currently stand at tile $$$q$$$ where $$$l_i \leq q \leq r_i$$$ when the attack happens, you lose. Of course, you do not want that.
Luckily, you know the attack pattern of the boss for each second. Moreover, you can do a move before each second to avoid the incoming attack. However, it will cost some energy if used. More exactly, before the $$$i$$$-th attack, you can do one of these moves:
If your energy goes below $$$0$$$, you will also lose. So, you need to stockpile on the energy count. However, grinding energy is very costly. So, calculate the minimum energy needed to survive the boss.
The first line contains an integer $$$t$$$ $$$(1 \leq t \leq 10^5)$$$ — the number of test cases.
The first line of each test case contains three integers $$$n,m,s$$$ $$$(2 \leq n \leq 2 \cdot 10^5, 1 \leq m \leq 2 \cdot 10^5, 1 \leq s \leq n)$$$ — the number of tiles on the arena, the number of seconds you need to survive, and your starting place.
For the next $$$m$$$ lines in each test case, each line consists of two integers $$$l_i,r_i$$$ $$$(1 \leq l_i \leq r_i \leq n, r_i-l_i+1 \lt n)$$$ — the lazer range at the $$$i$$$-th second.
It is guaranteed that the sum of $$$m$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.
Output a single integer, which is the minimum energy needed to survive. It is guaranteed that with the given constraints, you can always survive the boss.
57 3 44 72 53 42 2 22 22 22 2 12 22 26 9 41 34 61 55 63 61 11 46 65 68 1 52 7
3 1 0 12 3
For the first test case, this is one of the only optimal movement:
For the third test case, it is optimal to keep doing nothing.
| Name |
|---|


