Kotlin Heroes: Episode 7 |
---|

Finished |

The following languages are only available languages for the problems from the contest

Kotlin Heroes: Episode 7:

- Kotlin 1.7.20
- Kotlin 1.9.21

Virtual contest is a way to take part in past contest, as close as possible to participation on time. It is supported only ICPC mode for virtual contests.
If you've seen these problems, a virtual contest is not for you - solve these problems in the archive.
If you just want to solve some problem from a contest, a virtual contest is not for you - solve this problem in the archive.
Never use someone else's code, read the tutorials or communicate with other person during a virtual contest.

*special problem

implementation

math

No tag edit access

The problem statement has recently been changed. View the changes.

×
A. Travel to Bertown

time limit per test

2 secondsmemory limit per test

256 megabytesinput

standard inputoutput

standard outputVika 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$$$).

Example

Input

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.

Codeforces (c) Copyright 2010-2024 Mike Mirzayanov

The only programming contests Web 2.0 platform

Server time: Jul/24/2024 04:04:45 (i2).

Desktop version, switch to mobile version.

Supported by

User lists

Name |
---|