CF1869B.2D Traveling

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

2D Traveling

Piggy lives on an infinite plane with the Cartesian coordinate system on it.

There are nn cities on the plane, numbered from 11 to nn, and the first kk cities are defined as major cities. The coordinates of the ii-th city are (xi,yi)(x_i,y_i).

Piggy, as a well-experienced traveller, wants to have a relaxing trip after Zhongkao examination. Currently, he is in city aa, and he wants to travel to city bb by air. You can fly between any two cities, and you can visit several cities in any order while travelling, but the final destination must be city bb.

Because of active trade between major cities, it's possible to travel by plane between them for free. Formally, the price of an air ticket f(i,j)f(i,j) between two cities ii and jj is defined as follows:

$$$ f(i,j)= \begin{cases} 0, & \text{if cities }i \text{ and }j \text{ are both major cities} \\ |x_i-x_j|+|y_i-y_j|, & \text{otherwise} \end{cases}$$$

Piggy doesn't want to save time, but he wants to save money. So you need to tell him the minimum value of the total cost of all air tickets if he can take any number of flights.

Input

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

The first line of each test case contains four integers nn, kk, aa and bb (2n21052\le n\le 2\cdot 10^5, 0kn0\le k\le n, 1a,bn1\le a,b\le n, aba\ne b) — the number of cities, the number of major cities and the numbers of the starting and the ending cities.

Then nn lines follow, the ii-th line contains two integers xix_i and yiy_i (109xi,yi109-10^9\le x_i,y_i\le 10^9) — the coordinates of the ii-th city. The first kk lines describe major cities. It is guaranteed that all coordinates are pairwise distinct.

It is guaranteed that the sum of nn over all test cases does not exceed 21052\cdot 10^5.

Output

For each test case, print a single integer — the minimum value of the total price of all air tickets.

Note

In the first test case:

The major cities are marked red.

The optimal way to choose the flights is: 31253\rightarrow 1 \rightarrow 2 \rightarrow 5, which will cost 3+0+1=43+0+1=4. Note that the flight 121\rightarrow 2 costs 00, because both city 11 and 22 are major cities.

In the second test case, since there are only 22 cities, the only way is to take a flight from city 11 to 22.

In the third test case, since city 22 and 44 are both major cities, Piggy can directly take a flight from city 22 to 44, which costs 00.

In the fourth test case, Piggy can choose to take the following flights: 3213\rightarrow 2\rightarrow 1, and the cost is 11+11=2211+11=22.

Samples

5
6 2 3 5
0 0
1 -2
-2 1
-1 3
2 -2
-3 -3
2 0 1 2
-1000000000 -1000000000
1000000000 1000000000
7 5 4 2
154 147
-154 -147
123 456
20 23
43 20
998 244
353 100
3 1 3 1
0 10
1 20
2 30
4 3 2 4
0 0
-100 100
-1 -1
-1 0
4
4000000000
0
22
1

在线编程 IDE

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