New update is available. Click here to update.

Posted: 1 Jul, 2021

Difficulty: Hard

```
Input
4 2
0 1 2 2
2 4 4 5
Output
0
Explanation:
Here, Bob will first fall on the second prop, and he will travel till endpoint 2. Then he will fall on the first prop and travel till the endpoint 0. hence the final position will be X = 0.
```

```
The first line contains a single integer 'T' denoting the number of tests cases to be run. Then the test cases follow.
The first line of each test case contains two space-separated integers - initial X coordinate and N - number of segment props.
The next N lines of each test case describe the prop each by four integers x1, y1, x2, y2 - denoting the coordinates of the leftmost and rightmost point of the prop, respectively.
```

```
Props do not intersect or touch each other.
```

```
For each test case, print an integer ‘A’ denoting the final
coordinate
of Bob.
Answers for each test case will be printed in a separate line.
```

```
You are not required to print anything; it has already been taken
care of. Just implement the function and return the answer.
```

```
1 <= T <= 50
1 <= N <= 100
0 <= X <= 104
0 <= X1, Y1, X2, Y2 <= 10000
x1 < x2
Time Limit: 1 sec.
```

Categories:

Popular Courses: