Breaking Into Atoms

All submissions for this problem are available.
Let X be the set of all integers between 0 and n1. Suppose we have a collection S_{1}, S_{2}, ..., S_{m} of subsets of X. Say an atom A is a subset of X such that for each S_{i} we have either A is a subset of S_{i} or A and S_{i} do not have any common elements.
Your task is to find a collection A_{1}, ..., A_{k} of atoms such that every item in X is in some A_{i} and no two A_{i}, A_{j} with i ≠ j share a common item. Surely such a collection exists as we could create a single set {x} for each x in X. A more interesting question is to minimize k, the number of atoms.
Input
The first line contains a single positive integer t ≤ 30 indicating the number of test cases. Each test case begins with two integers n,m where n is the size of X and m is the number of sets S_{i}. Then m lines follow where the i'th such line begins with an integer v_{i} between 1 and n (inclusive) indicating the size of S_{i}. Following this are v_{i} distinct integers between 0 and n1 that describe the contents of S_{i}.
You are guaranteed that 1 ≤ n ≤ 100 and 1 ≤ m ≤
30. Furthermore, each number between 0 and n1 will appear in at least one set S_{i}.
Output
For each test case you are to output a single integer indicating the minimum number of atoms that X can be partitioned into to satisfy the constraints.
Example
Input: 2 5 2 3 0 1 2 3 2 3 4 4 3 2 0 1 2 1 2 2 2 3 Output: 3 4
Author:  friggstad 
Tester:  pieguy 
Editorial  http://discuss.codechef.com/problems/ATOMS 
Tags  cook07, easy, friggstad 
Date Added:  30012011 
Time Limit:  1.04632 sec 
Source Limit:  50000 Bytes 
Languages:  C, CPP14, JAVA, PYTH, PYTH 3.6, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, SCALA, D, PERL, FORT, WSPC, ADA, CAML, ICK, BF, ASM, CLPS, PRLG, ICON, SCM qobi, PIKE, ST, NICE, LUA, BASH, NEM, LISP sbcl, LISP clisp, SCM guile, JS, ERL, TCL, PERL6, TEXT, PYP3, CLOJ, FS 
Comments
 Please login at the top to post a comment.
SUCCESSFUL SUBMISSIONS
Fetching successful submissions
HELP
If you are still having problems, see a sample solution here. 