308516: CF1533A. Travel to Bertown

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

A. Travel to Bertowntime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard output

Vika has decided to go on a trip to Bertown. She comes to Bertown on the $k$-th day. Vika does not want to spend money on hotels, fortunately she has $n$ friends who live in Bertown and allow Vika to stay at their houses. The $i$-th friend told Vika that she could stay at their house from the $l_i$-th day till the $r_i$-th day, inclusive.

Vika decided that she would stay at no more than one friend's house. Help Vika determine the maximum number of days that she will be able to stay in Bertown.

Input

The first line contains a single integer $t$ ($1 \le t \le 500$) — the number of test cases.

The first line of each test case contains two integers $n$ and $k$ ($1 \le n, k \le 100$) — the number of Vika's friends and the day when Vika comes to Bertown.

Then follow $n$ lines, each containing two integers $l_i$ and $r_i$ ($1 \le l_i \le r_i \le 100$) denoting the period when Vika can stay at the $i$-th friend's house.

Output

For each test case, output a single integer — the maximum number of days that Vika can stay in Bertown (or $0$ if none of Vika's friends can host her on day $k$).

ExampleInput
3
3 3
1 4
2 6
4 10
2 4
2 3
5 8
2 4
4 4
1 3
Output
4
0
1
Note

In the first example, Vika can stay at the $2$-nd friend's house from $3$-rd to $6$-th day.

In the second example, none of Vika's friends can host her on the $4$-th day.

In the third example, Vika can stay at the $1$-st friend's house, but only for the $4$-th day.

Input

暂时还没有翻译

加入题单

上一题 下一题 算法标签: