C-algae

No attempts yetTime limit3sMemory limit128 MB

Problem

C-algae is the Byteotians' favourite dish of their national cuisine. A c-algae has a very specific structure, defined recursively.

  • A single cell is a c-algae.
  • Two c-algae K1K_1 and K2K_2 can be combined into a new c-algae KK in exactly one of the two following ways:
    1. Disjoint union — take all cells and all connections of both K1K_1 and K2K_2.

    2. Join — take all cells and all connections of both K1K_1 and K2K_2, and in addition connect every cell of K1K_1 to every cell of K2K_2.

Recently the hostile country of Bitotia started selling algae that imitate c-algae so closely that a fake is hard to tell apart from a genuine c-algae. The Byteotian government has therefore asked you to write a program that verifies whether a given algae is really a c-algae.

Write a program that reads the descriptions of several algae from standard input, determines which of them are proper c-algae, and writes the answers to standard output. Every connection is undirected.

Input

The first line contains a single integer kk (1k101 \le k \le 10) — the number of algae to examine. The descriptions of the kk algae follow.

Each description begins with a line containing two integers nn and mm (1n100001 \le n \le 10\,000, 0m1000000 \le m \le 100\,000) — the number of cells and the number of connections. The cells are numbered from 11 to nn. Each of the next mm lines contains two integers aa and bb (aba \ne b, 1a,bn1 \le a, b \le n) describing an undirected connection between cells aa and bb. Each connection is given exactly once.

Output

Output kk lines. In the ii-th line print:

  • TAK if the ii-th algae is a proper c-algae,
  • NIE otherwise.