Connected or Not Connected

Time limit1sMemory limit128 MB

Summary
Given a graph with n sites and k edges, decide whether every site can reach every other.
Level

Easy3 of 10

Topics
Graph, DFS, Union-find
Solved
No attempts yet

Problem

There is a world containing nn sites that are interconnected by a number of (virtual) pathways. Each pathway is a bi-directional connection between two sites: if there is a connection between site aa and site bb, then you can travel from aa to bb and from bb to aa.

Using only the given connections, decide whether there is a path from every site to every other site — that is, whether the graph is connected as a single whole.

Input

The first line contains the number of test cases TT (T≤50T \le 50).

Each of the following lines contains one test case. The first number in a test case is the number of sites nn (n≤100n \le 100); the sites are numbered from 00 to n−1n-1. The second number is the number of connections kk (k≤200k \le 200). After that come kk connections, each given as a pair of integers.

Connections may repeat, and there may be self-connections (a connection from a site to itself).

Output

For each test case, check whether there is a path from every site to every other site, and print Connected. if so, or Not connected. otherwise, on its own line.

Examples1

  1. Example 1

    Input
    3
    5 4 0 1 1 2 2 3 3 4
    6 6 0 1 1 2 2 0 3 4 4 5 5 3
    5 9 0 1 1 2 2 3 3 4 1 0 2 1 3 2 2 3 4 3 
    
    Expected output
    Connected.
    Not connected.
    Connected.