Tree

Given up to 10 graphs, decide for each whether it is a tree, allowing self-loops and duplicate edges.

Medium4GraphUnion-findDFSInterviewNo attempts yetTime limit2sMemory limit512 MB

Problem

A tree is a graph with the following three properties.

  1. It is connected. Starting from any node you can reach every other node along edges.
  2. Removing one edge breaks the connection. Some node can no longer be reached.
  3. Adding one edge between two existing nodes A and B creates a cycle. A cycle exists when there is more than one way to get from A to B.

Given a graph, decide whether it is a tree.

Input

The first line contains an integer TT, the number of graphs to check. TT is at most 10.

Each graph is given in the following format.

The first line contains the number of nodes NN, where 1N10001 \le N \le 1000. The nodes are numbered from 1 to NN.

The next line contains the number of edges MM, where 0M1060 \le M \le 10^6.

The next MM lines each contain two integers AA and BB, the two nodes that one edge connects. AA and BB can be equal, and the same pair can appear more than once.

The sum of MM over all graphs is at most 10610^6.

Output

For each graph, print one line: tree if the graph is a tree, and graph otherwise.