Flipping Cards

Decide whether each card can show one of its two pictures so that all n face-up pictures differ.

Medium5GraphUnion-findNo attempts yetTime limit3sMemory limit256 MB

Problem

Mike plays a card game with his young daughter Jesse. The rules are short. Each player is dealt a hand of cards, and every card has one picture on each side. The players take turns laying cards on the table, and whoever runs out of cards first wins.

On a turn a player picks some of the cards in hand and lays them on the table. A card lands with one of its two sides face up. The only rule is that no two cards on the table show the same picture.

Decide whether Mike can lay down his entire hand on his very first turn.

Input

The first line contains an integer TT (1T101 \le T \le 10), the number of test cases.

Each test case starts with a line holding an integer nn (1n500001 \le n \le 50000), the number of cards in Mike's hand. Each of the next nn lines describes one card with two integers pip_i and qiq_i (1pi,qi2n1 \le p_i, q_i \le 2n), the pictures on its two sides. Pictures are written as integers.

Output

For each test case print one line. Print possible if Mike can lay down his entire hand in one turn, and impossible otherwise.