Montesco vs Capuleto
Romeo and Juliet have finally decided to get married. But preparing the wedding party will not becso easy, as it is well-known that their respective families — the Montesco and the Capuleto — are bloody enemies. In this problem you will have to decide which person to invite and which person not to invite, in order to prevent a slaugther.
We have a list of people who can be invited to the party or not. For every person , we have a list of his enemies: . The “enemy” relationship has the following properties:
Anti-transitive. If is an enemy of , and is an enemy of , then is a friend of . Also, the enemies of the friends of are his enemies, and the friends of the friends of a are his friends.
Symmetrical. If is an enemy of , then is an enemy of (although it may not be indicated in his list of enemies).
One person will accept an invitation to the party if, and only if, he is invited, all his friends are invited and none of his enemies is invited. You have to find the maximum number of people that can be invited, so that all of them accept their invitation.
For instance, if , and we know that: is enemy of is enemy of , and is enemy of , then we could invite a maximum of people. These people could be and , but for this problem we only want the number of people invited.
Input
The first line contains the number of test cases. A blank line follows this number, and a blank line is also used to separate test cases. The first line of each test case contains an integer , indicating the number of people who have to be considered. For each of these people, there is a line with his list of enemies. The first line contains the list of enemies of person , the second line contains the list of enemies of person , and so on. Each list of enemies starts with an integer (the number of known enemies of that person) and then, there are integers (the enemies of that person). So, for example, if a person’s enemies are and , his list of enemies would be: .
Output
For each test case, the output should consist of a single line containing an integer, the maximum number of people who can be invited, so that all of them accept their invitation.