public static void main(String[] args) throws IOException {
		Scanner in = new Scanner(System.in);
		StringBuilder out = new StringBuilder();
		int nTest = in.nextInt();
		Edmons_karp f;
		for (int i = 0; i < nTest; i++) {
			int nNodes = in.nextInt();
			f = new Edmons_karp(nNodes);
			for (int j = 0; j < nNodes - 1; j++) {
				int nNeigh = in.nextInt(), t, v;
				for (int k = 0; k < nNeigh; k++) {
					t = in.nextInt() - 1;
					v = (j == 0 || t == nNodes - 1) ? 1 : 1 << 20;
					f.ady[j].add(t);
					f.ady[t].add(j);
					f.g[j][t] = v;
				}
			}
			out.append(f.edmons_karp(0, nNodes - 1) + "\n");
		}
		System.out.print(out);
	}