← Home
write a go solution for Description:
You have n sets of integers S_1,S_2,ldots,S_n. We call a set S attainable, if it is possible to choose some (possibly, none) of the sets S_1,S_2,ldots,S_n so that S is equal to their union^dagger. If you choose none of S_1,S_2,ldots,S_n, their union is an empty set.

Find the maximum number of elements in an attainable S such that SneqS_1cupS_2cupldotscupS_n.

^dagger The union of sets A_1,A_2,ldots,A_k is defined as the set of elements present in at least one of these sets. It is denoted by A_1cupA_2cupldotscupA_k. For example, 2,4,6cup2,3cup3,6,7=2,3,4,6,7.

Input Format:
Each test contains multiple test cases. The first line contains the number of test cases t (1<=t<=100). The description of the test cases follows.

The first line of each test case contains a single integer n (1<=n<=50).

The following n lines describe the sets S_1,S_2,ldots,S_n. The i-th of these lines contains an integer k_i (1<=k_i<=50) — the number of elements in S_i, followed by k_i integers s_i,1,s_i,2,ldots,s_i,k_i (1<=s_i,1<s_i,2<ldots<s_i,k_i<=50) — the elements of S_i.

Output Format:
For each test case, print a single integer — the maximum number of elements in an attainable S such that SneqS_1cupS_2cupldotscupS_n.

Note:
In the first test case, S=S_1cupS_3=1,2,3,4 is the largest attainable set not equal to S_1cupS_2cupS_3=1,2,3,4,5.

In the second test case, we can pick S=S_2cupS_3cupS_4=2,3,4,5,6.

In the third test case, we can pick S=S_2cupS_5=S_2cupS_3cupS_5=3,5,6,8,9,10.

In the fourth test case, the only attainable set is S=varnothing.. Output only the code with no comments, explanation, or additional text.