Escape from Enemy Territory

Time limit3sMemory limit128 MB

Problem

A small team of commandos has infiltrated deep into enemy territory. They have just finished their mission and must now return to their rendezvous point without being caught. To stay safe, they want to follow a route that keeps them as far as possible from every enemy base.

The area is modeled as a rectangular grid of integer coordinates $(x, y)$ with $0 \le x < X$ and $0 \le y < Y$. At each step a commando moves one unit up, down, left, or right, and the route may never leave the grid. Distances use the Manhattan metric:

$$\operatorname{dist}((x_1, y_1), (x_2, y_2)) = |x_2 - x_1| + |y_2 - y_1|.$$

The separation of a route is the smallest Manhattan distance between any cell it visits (including the start and the rendezvous point) and any enemy base. The commandos first want to maximize this separation. Among all routes that achieve the maximum separation, they then want one with the fewest steps. Enemy bases outside the grid do not exist and can be ignored.

Input

The first line contains the number of test cases $T$ $(1 \le T \le 100)$. Each test case is given as follows:

  • One line with three integers $N$, $X$, $Y$ $(1 \le N \le 10000,\ 1 \le X, Y \le 1000)$: the number of enemy bases and the grid size. A coordinate $(x, y)$ lies on the grid if and only if $0 \le x < X$ and $0 \le y < Y$.
  • One line with four integers $x_i\ y_i\ x_r\ y_r$: the commandos' starting position $(x_i, y_i)$ and the rendezvous point $(x_r, y_r)$.
  • $N$ lines, each with two integers $x\ y$ giving the position of one enemy base.

All given coordinates lie on the grid and are pairwise distinct.

Output

For each test case, print one line with two integers separated by a single space: the maximum achievable separation from any enemy base, followed by the number of steps in the shortest route that achieves that separation.