Under construction

Still being built. Things may change

Flipping Cards

Time limit3sMemory limit256 MB

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

Medium5 of 10

Topics
Graph, Union-find
Solved
No attempts yet

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 (1≤T≤101 \le T \le 10), the number of test cases.

Each test case starts with a line holding an integer nn (1≤n≤500001 \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 (1≤pi,qi≤2n1 \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.

Examples3

  1. Example 1

    Input
    3
    3
    1 2
    1 3
    2 3
    3
    1 2
    1 2
    1 2
    1
    1 1
    
    Expected output
    possible
    impossible
    possible
    
  2. Example 2

    Input
    1
    1
    1 2
    
    Expected output
    possible
    
  3. Example 3

    Input
    1
    2
    1 1
    1 1
    
    Expected output
    impossible