CF1819B.The Butcher

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Anton plays his favorite game "Defense of The Ancients 2" for his favorite hero — The Butcher. Now he wants to make his own dinner. To do this he will take a rectangle of height hh and width ww , then make a vertical or horizontal cut so that both resulting parts have integer sides. After that, he will put one of the parts in the box and cut the other again, and so on.

More formally, a rectangle of size h×wh \times w can be cut into two parts of sizes x×wx \times w and (hx)×w(h - x) \times w , where xx is an integer from 11 to (h1)(h - 1) , or into two parts of sizes h×yh \times y and h×(wy)h \times (w - y) , where yy is an integer from 11 to (w1)(w - 1) .

He will repeat this operation n1n - 1 times, and then put the remaining rectangle into the box too. Thus, the box will contain nn rectangles, of which n1n - 1 rectangles were put in the box as a result of the cuts, and the nn -th rectangle is the one that the Butcher has left after all n1n - 1 cuts.

Unfortunately, Butcher forgot the numbers hh and ww , but he still has nn rectangles mixed in random order. Note that Butcher didn't rotate the rectangles, but only shuffled them. Now he wants to know all possible pairs (h,w)(h, w) from which this set of rectangles can be obtained. And you have to help him do it!

It is guaranteed that there exists at least one pair (h,w)(h, w) from which this set of rectangles can be obtained.

输入格式

Each test consists of multiple test cases. The first line 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 a single integer nn ( 1n21051 \le n \le 2 \cdot 10^5 ) — the number of rectangles obtained.

The ii -th of the next nn lines contains two integers aia_i and bib_i ( 1ai,bi1061 \le a_i, b_i \le 10^6 ) — the height and width of the ii -th rectangle.

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

输出格式

For each test case, on the first line output a single integer mm — the number of pairs (h,w)(h, w) denoting the sizes of rectangles from which the given rectangles can be obtained. Two rectangles are considered different if they have different heights or widths.

On each of the following mm lines print output integers hih_i and wiw_i — the height and width of the rectangle from which the given rectangles can be obtained. You can output the rectangles in any order.

输入输出样例

  • 输入#1

    4
    3
    1 2
    3 5
    1 3
    3
    1 1
    1 1
    1 1
    1
    10 10
    4
    3 2
    5 5
    2 2
    8 7

    输出#1

    1
    4 5
    2
    1 3
    3 1
    1
    10 10
    1
    13 7

说明/提示

In the first test case, Butcher could only have a rectangle of size 4×54 \times 5 . Then the cuts could look like this (first the green cut was made, then the red one):

In the second test case, Butcher could have either a rectangle of 1×31 \times 3 or 3×13 \times 1 . The cuts would have looked like this (first the green cut was made, then the red cut):

In the third test case, Butcher did not make any cuts, so the rectangle is 10×1010 \times 10 .

首页