QOJ.ac

QOJ

Limite de temps : 1 s Limite de mémoire : 128 MB Points totaux : 100

#4132. Skipping the Exam

Statistiques

The college entrance examination is coming again, which is really not good news for those who don't study hard. To ensure Xiao Yang studies diligently at home, his relatives have decided to station themselves in his house to supervise him. This includes his grandparents, maternal grandparents, uncle, sister-in-law, aunt, and so on.

Xiao Yang simply cannot bear it anymore; how is this life any different from being in prison? For the sake of his dear Xiao Hong and his Dota, he has decided to break out!

Assume Xiao Yang's house is an $n \times m$ matrix, with the bottom-left corner at $(0, 0)$ and the top-right corner at $(x_1, y_1)$. There are $n$ relatives stationed within the matrix (at distinct positions, none of which are on the edges of the matrix). Every point in Xiao Yang's house is monitored by his relatives, specifically by the relative closest to that point.

That is to say, if Xiao Yang is at position $(3, 3)$, and relative A is at $(3, 0)$, the distance from A to Xiao Yang is $3$. If relative B is at $(6, 7)$, the distance from B to Xiao Yang is $5$. Since the distance to A is less than the distance to B, the position $(3, 3)$ is monitored by A. If there is a tie for the "closest distance" among several relatives, that position is monitored by all of those relatives simultaneously.

Given Xiao Yang's coordinates $(x_0, y_0)$, and knowing that the fewer people who discover him, the higher his chances of a successful escape, you need to design an escape route for Xiao Yang to reach the edge of the matrix such that the number of people who discover him is minimized.

Note: Xiao Yang can move in any direction, meaning any position on the route can be represented by real numbers.

It is guaranteed that initially, Xiao Yang is monitored by only one relative.

Input

The first line contains a positive integer $t \leq 3$, representing the number of test cases.

For each of the $t$ test cases:

  • The first line contains $n$, the number of Xiao Yang's relatives.
  • The next line contains four positive integers, representing the coordinates of the top-right corner of the matrix $(x_1, y_1)$ and Xiao Yang's coordinates $(x_0, y_0)$.
  • The next $n$ lines each contain two positive integers, representing the position of a relative.

Output

For each test case, output a single positive integer representing the minimum number of people who discover Xiao Yang during his escape.

Examples

Input 1

2
4
10 10 5 5
5 6
3 5
7 5
5 3
17
14 12 7 6
7 11
6 9
7 7
1 10
2 20
1 6
2 6
1 1
2 2
5 1
5 2
13 1
12 2
12 7
13 7
12 11
13 11

Output 1

1
2

Subtasks

  • The first $10\%$ of the data satisfies $n \leq 3$.
  • The first $50\%$ of the data satisfies $n \leq 200$.
  • The remaining data satisfies $n \leq 600$.

Reminder: According to SDOI tradition, the test data is graded in difficulty.

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.