Universal Cup Judging System

Universal Cup

시간 제한: 3.0 s 메모리 제한: 1024 MB 총점: 100 난이도: [표시] 해킹 가능 ✓
통계

In a new Minecraft update, spiders have finally gotten the long-awaited ability to weave webs by hand. However, to preserve the spirit of the game, the developers allowed them to stretch threads only strictly horizontally or strictly vertically.

A spider has a rectangular area of size $W \times H$, which we will consider as the rectangle with corners $(0, 0)$, $(W, 0)$, $(W, H)$, and $(0, H)$. On the boundary of this rectangle, $n$ points are marked — places where the spider must definitely stretch its web.

The spider may draw any number of horizontal and vertical thread segments. The segments may be arbitrary — they may intersect, lie along the rectangle’s boundary, or even hang in the air. The spider must weave the web so that all marked points lie in one connected component. In other words, it must be possible to get from any marked point to any other marked point by moving only along the drawn segments.

Naturally, the developers want to save on web texture. Therefore, you need to find the minimum possible total length of all threads drawn.

Input

The first line contains an integer $t$ ($1 \le t \le 2 \cdot 10^5$) — the number of test cases. Then the test cases follow.

The first line of each test case contains three integers $n$, $W$, $H$ ($1 \le n \le 10^6$, $1 \le W, H \le 10^9$) — the number of marked points and the rectangle dimensions.

The next $n$ lines contain pairs of integers $x_i$, $y_i$ ($0 \le x_i \le W$, $0 \le y_i \le H$) — the coordinates of the marked points.

It is guaranteed that all points are distinct and lie on the boundary of the rectangle. It is also guaranteed that the points are listed in counterclockwise order along the boundary of the rectangle, starting from the bottom-left corner $(0, 0)$. The sum of $n$ over all test cases does not exceed $10^6$.

Output

For each test case, output one number — the minimum possible total length of threads that can be stretched.

Examples

Input 1

3
1 2 1
1 0
2 1 2
0 0
1 2
3 2 2
1 0
2 1
0 1

Output 1

0
3
3

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.