
class Apartment:
    def __init__(self, line, bx, by, ex, ey, index):
        x, y = [int(x) for x in line.split(" ")]
        self.x = x
        self.y = y

        m_b = manhattan(x, y, bx, by)
        m_e = manhattan(x, y, ex, ey)

        self.larger_distance = max(m_b, m_e)
        self.abs_difference = abs(m_b - m_e)
        self.index = index

    def __lt__(self, other):
        return self.larger_distance < other.larger_distance\
            or (self.larger_distance == other.larger_distance and self.abs_difference < other.abs_difference)\
            or (self.larger_distance == other.larger_distance and self.abs_difference == other.abs_difference and self.index < other.index)


def manhattan(x1, y1, x2, y2):
    return abs(x1-x2) + abs(y1-y2)


def one_case():
    n, bx, by, ex, ey = [int(x) for x in input().split(" ")]

    places = []
    for i in range(n):
        places.append(Apartment(input(), bx, by, ex, ey, i))

    places.sort()

    for p in places:
        print(f"{p.x} {p.y}")


cases = int(input())
for _ in range(cases):
    one_case()
