army-of-france

Announcement
************Second Round will be ONLINE instead of ONSITE*************
Problem Statement

It’s 18th Century and the king of France Louis XIV has to send an Army for the Battle of Carpi. The Army consists of N (numbered 1-N) army-men and there are M (numbered 1-M) Horses. Each army-man likes a subset of horses from the horses available, and will go to the battle ground if assigned to a horse from the subset he likes. So given the list of horses each army man likes, tell the maximum number of army-men the king can send to the battle-ground.

INPUT

The first line contains T, the number of test cases.

The first line of each test case contains two space separated integers N M.

Then N lines follow with ith line as

Ki Ai1 Ai2 Ai3 . . . . . . . . . . AiKi 

where Ki is the number of horses ith army-man likes and Aij is the jth horse he likes.

OUTPUT

For each test case output in a single line the required answer.

CONSTRAINTS

1 ≤ T ≤ 10

1 ≤ N ≤ 1000

1 ≤ M ≤ 1000

1 ≤ Ki ≤ N

1 ≤ Aij ≤ M

SAMPLE INPUT
1
3 2
1 1
2 1 2
1 2

SAMPLE OUTPUT
2

Explanation

In the given sample case, there are 3 army men and 2 horses. The 1st army man likes 1st horse, 2nd likes both and 3rd likes only the second horse. So we can send maximum 2 army men in the battle ground. either 1st army man with 1st horse and 2nd army man with 2nd horse or 2nd army man with 1st horse and 3rd army man with the 2nd horse.

Source: hackerearth | Difficulty: UNKNOWN_DIFFICULTY


Solutions: