This page is still under construction.

Parts of this page are still being built. What you see may change.

Magic Graphs

Time limit2sMemory limit64 MB

Summary
Pick one label from each of K pairs so that no two chosen labels are the positive and negative of the same number.
Level

Medium7 of 10

Topics
Graph, DFS
Solved
No attempts yet

Problem

A k-partite graph is a graph whose vertices split into KK disjoint sets so that no two vertices inside the same set are adjacent. This problem only deals with a special k-partite graph in which every set holds exactly two vertices. Call such a graph a magic graph.

Let P={1,2,3,4,… }P = \{1, 2, 3, 4, \dots\} be the set of positive labels, let N={1′,2′,3′,4′,… }N = \{1', 2', 3', 4', \dots\} be the set of negative labels, and let L=P∪NL = P \cup N. A magic graph is a k-partite graph G=(V,E)G = (V, E) with V=V1∪V2∪⋯∪VKV = V_1 \cup V_2 \cup \dots \cup V_K, where every ViV_i is a subset of LL with ∣Vi∣=2|V_i| = 2. The edge {l1,l2}\{l_1, l_2\} exists only when both conditions hold. First, l1l_1 and l2l_2 belong to different sets. Second, l1l_1 and l2l_2 are not the positive and the negative label of the same number.

For example, look at the tripartite magic graph with V1={1,2}V_1 = \{1, 2\}, V2={1′,2′}V_2 = \{1', 2'\} and V3={1,2′}V_3 = \{1, 2'\}. Two vertices with the same label in different sets are different vertices, so the vertex labeled 1 in V1V_1 is not the vertex labeled 1 in V3V_3. The edges follow the rule above. The edges {1,1}\{1, 1\} and {1,2′}\{1, 2'\} exist because the two labels sit in different sets and are not the positive and the negative label of one number. The edge {1,1′}\{1, 1'\} does not exist, because 1 and 1′1' are the positive and the negative label of the same number.

Given a k-partite magic graph GG, decide whether GG has a clique of size KK.

Input

The first line contains the number of test cases TT, where T≤10T \le 10.

Each test case has the following format.

  • The first line contains the integer KK, where 2≤K≤240002 \le K \le 24000.
  • Each of the next KK lines describes one set ViV_i and holds two labels separated by a single space. A positive label is written as a positive number, and a negative label as a minus sign followed by a positive number.

Output

Print one line with a string of length TT made of the characters Y and N. The ii-th character answers the ii-th test case: Y if the given magic graph has a clique of size KK, and N otherwise.

Examples1

  1. Example 1

    Input
    2
    3
    1 2
    -1 -2
    1 -2
    4
    1 -2
    1 2
    -1 2
    -1 -2
    
    Expected output
    YN