Odd-Length Cycle

Time limit1sMemory limit128 MB

Summary
For each of t undirected graphs, decide whether it contains an odd-length cycle (equivalently, is not bipartite).
Level

Medium4 of 10

Topics
Graph, BFS, DFS
Solved
No attempts yet

Problem

Given an undirected graph, determine whether it contains a cycle of odd length.

You are given a number tt of test cases, followed by tt graphs. For each graph, decide whether an odd-length cycle exists in it.

Input

The first line contains the number of test cases tt (1≤t≤1001 \le t \le 100). Then tt undirected graphs follow.

Each graph starts with two integers nn and mm, the number of vertices and the number of edges (1≤n≤1051 \le n \le 10^5, 1≤m≤2×1051 \le m \le 2 \times 10^5). Each of the next mm lines contains two integers between 11 and nn, the two endpoints of one edge.

Output

For each graph, print the answer on its own line. Print TAK if the graph contains a cycle of odd length (equivalently, the graph is not bipartite), and NIE otherwise.

Examples1

  1. Example 1

    Input
    2
    4 6
    1 2
    1 3
    1 4
    2 3
    2 4
    3 4
    4 4
    1 2
    2 3
    3 4
    4 1
    
    Expected output
    TAK
    NIE