Under construction

Still being built. Things may change

Graph Cards

Time limit30sMemory limit1024 MB

Summary
Count how many of the given connected graphs are pairwise non-isomorphic, where each card gives its edge list and has as many edges as nodes.
Level

Medium7 of 10

Topics
Graph, Tree, String, Hash map
Solved
No attempts yet

Problem

A deck of graph cards is placed on the table. Each graph card χ\chi is decorated with an undirected simple graph GχG_\chi. Each GχG_\chi is connected and has the same number of nodes and edges. Different graph cards may have different numbers of nodes.

Two graph cards are identical if and only if their graphs G1=(V1,E1)G_1 = (V_1, E_1) and G2=(V2,E2)G_2 = (V_2, E_2) are isomorphic. That is, there is a bijection ff from V1V_1 to V2V_2 such that for all x,y∈V1x, y \in V_1, (x,y)∈E1(x, y) \in E_1 if and only if (f(x),f(y))∈E2(f(x), f(y)) \in E_2. The goal is to count the distinct graph cards in the deck.

Input

The first line contains an integer tt, the number of test cases. Each test case begins with a line containing the number of graph cards n>0n > 0. Then nn lines follow, each describing one graph card in this format:

k u1 v1 u2 v2 ... uk vk

Here k>0k > 0 is the number of nodes, which is also the number of edges. For each i∈[1,k]i \in [1, k], (ui,vi)(u_i, v_i) is an edge. Node identifiers are integers in [1,k][1, k].

Output

For each test case, print the number of distinct graph cards in the deck on its own line.

Constraints

  • 0<t≤300 < t \le 30
  • 0<n,k≤1060 < n, k \le 10^6
  • For each test case, the node counts of the nn graph cards sum to at most 10610^6.

Examples2

  1. Example 1

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

    Input
    2
    2
    4 1 2 2 3 3 1 1 4
    5 1 2 2 3 3 1 2 4 2 5
    3
    9 1 2 2 5 5 7 7 6 6 3 3 1 2 4 7 9 9 8
    9 1 4 4 2 2 3 3 5 5 7 7 6 6 4 7 8 8 9
    9 1 2 2 5 5 4 4 1 4 7 7 8 8 6 8 9 5 3
    
    Expected output
    2
    2