Division Avoidance

시간 제한2초메모리 제한2048 MB

요약
분열을 반복해 금지된 격자 칸을 하나도 포함하지 않는 세포 집합을 만들 수 있는지 판정한다.
난이도

어려움10점 중 9점

유형
그리디, 수학, 조합론
정답자
아직 제출이 없습니다

문제

A newly discovered organism can be represented as a set of cells on an infinite grid. There is a coordinate system on the grid such that each cell has two integer coordinates xx and yy. A cell with coordinates x=ax = a and y=by = b will be denoted as (a,b)(a, b).

Initially, the organism consists of a single cell (0,0)(0, 0). Then zero or more divisions can happen. In one division, a cell (a,b)(a, b) is removed and replaced by two cells (a+1,b)(a + 1, b) and (a,b+1)(a, b + 1).

For example, after the first division, the organism always consists of two cells (1,0)(1, 0) and (0,1)(0, 1), and after the second division, it is either the three cells (2,0)(2, 0), (1,1)(1, 1) and (0,1)(0, 1), or the three cells (1,0)(1, 0), (1,1)(1, 1) and (0,2)(0, 2).

A division of a cell (a,b)(a, b) can only happen if the cells (a+1,b)(a + 1, b) and (a,b+1)(a, b + 1) are not yet part of the organism. For example, the cell (1,0)(1, 0) cannot divide if the organism currently consists of the three cells (1,0)(1, 0), (1,1)(1, 1) and (0,2)(0, 2), since the cell (1,1)(1, 1) that would be one of the results of this division is already part of the organism.

You are given a set of forbidden cells (c_i,d_i)(c\_i , d\_i). Is it possible for the organism to contain none of those cells after zero or more divisions?

입력

Each test contains multiple test cases. The first line contains an integer tt (1≤t≤10,0001 ≤ t ≤ 10\\, 000) — the number of test cases. The descriptions of the tt test cases follow.

The first line of each test case contains an integer nn (1≤n≤1061 ≤ n ≤ 10^6) — the number of forbidden cells.

The next nn lines contain two integers each. The ii-th of such lines contains c_ic\_i and d_id\_i (0≤c_i,d_i≤1090 ≤ c\_i , d\_i ≤ 10^9) — the coordinates of the ii-th forbidden cell. It is guaranteed that all forbidden cells are distinct.

It is guaranteed that the sum of values of nn over all test cases does not exceed 10610^6.

출력

For each test case, print YES if it is possible for the organism to contain no forbidden cells after zero or more divisions. Otherwise, print NO.

예제1

  1. 예제 1

    입력
    2
    4
    0 0
    1 0
    0 1
    1 1
    16
    0 0
    0 1
    0 2
    0 3
    1 0
    1 1
    1 2
    1 3
    2 0
    2 1
    2 2
    2 3
    3 0
    3 1
    3 2
    3 3
    
    예상 출력
    YES
    NO