logo AlgoBeat OnlineJudge
登录 注册

#215832. [JAG 2025 Summer Camp #2] Hanako' s Art II

内存限制:1024 MiB 时间限制:2000 ms 标准输入输出
题目类型:VJudge(洛谷) 评测方式:VJudge
上传者: 匿名

题目描述

There are points in the -plane. Any two points have neither the same -coordinate nor the same -coordinate. Each point has a color represented by an integer between and (inclusive). For each of the colors, there are exactly two points of that color.

An artist, Hanako, is willing to create a masterpiece by drawing polygonal chains in the -plane. According to her aesthetic sense, a masterpiece must satisfy all the following conditions.

  • Any two points having the same color are the endpoints of one of the polygonal chains.
  • Each polygonal chain consists of exactly two line segments, each of which is parallel to the - or -axis.
  • No two polygonal chains intersect.

Your task is to determine whether Hanako can create such a masterpiece.

输入格式

The input consists of multiple test cases. The first line of input contains an integer () representing the number of test cases. After that, test cases follow. Each of them is given in the following format.

The first line contains an integer () representing the number of polygonal chains which Hanako has to draw. Each of the following lines contains two integers and satisfying and . Each line represents that the -th point has the coordinate and the color .

It is guaranteed that if . In addition, no three points have the same color.

The sum of over all the test cases does not exceed .

输出格式

If Hanako can create a masterpiece, print "Yes"; otherwise, print "No".

样例

样例输入 1

2
3
2 1
1 2
4 3
6 1
3 3
5 2
3
2 3
6 1
5 2
1 1
4 3
3 2

样例输出 1

Yes
No

数据范围与提示

One of the possible masterpieces in Sample Input 1 is depicted in Figure J-1.

:::align{center}

Figure J-1: Illustration of Sample Input 1 :::