CF2004B.Game with Doors

传统题 时间 2000 ms 内存 256 MiB 5 尝试 1 已通过 1 标签

Game with Doors

There are 100100 rooms arranged in a row and 9999 doors between them; the ii-th door connects rooms ii and i+1i+1. Each door can be either locked or unlocked. Initially, all doors are unlocked.

We say that room xx is reachable from room yy if all doors between them are unlocked.

You know that:

  • Alice is in some room from the segment [l,r][l, r];
  • Bob is in some room from the segment [L,R][L, R];
  • Alice and Bob are in different rooms.

However, you don't know the exact rooms they are in.

You don't want Alice and Bob to be able to reach each other, so you are going to lock some doors to prevent that. What's the smallest number of doors you have to lock so that Alice and Bob cannot meet, regardless of their starting positions inside the given segments?

Input

The first line contains a single integer tt (1t1041 \le t \le 10^4) — the number of test cases.

The first line of each test case contains two integers ll and rr (1l<r1001 \le l \lt r \le 100) — the bounds of the segment of rooms where Alice is located.

The second line of each test case contains two integers LL and RR (1L<R1001 \le L \lt R \le 100) — the bounds of the segment of rooms where Bob is located.

Output

For each test case, print a single integer — the smallest number of doors you have to lock so that Alice and Bob cannot meet, regardless of their starting positions inside the given segments.

Note

In the first test case, it is sufficient to lock the door between rooms 22 and 33.

In the second test case, the following doors have to be locked: (2,3)(2,3), (3,4)(3,4), (4,5)(4,5).

In the third test case, the following doors have to be locked: (5,6)(5, 6) and (6,7)(6,7).

Samples

4
1 2
3 4
2 5
2 5
3 7
6 7
4 5
2 8
1
3
2
3

在线编程 IDE

建议全屏模式获得最佳体验