News
In the city, a new bus system has been introduced where all buses operate on cyclic routes. Some routes have stops in common. When two or more buses meet at the same stop, the drivers exchange all the news they know at that moment. After leaving the stop, all drivers will have the same information.
All buses start their routes at the same time, and initially, each driver knows a unique piece of news that no other driver knows.
The buses move in a synchronized manner, meaning the time it takes to travel from one stop to the next is the same for all buses.
There are D drivers (and therefore D buses), numbered from 1 to D, and S stops, numbered from 1 to S.
Write a program called BUS that determines whether each driver can eventually learn all the news from their colleagues if the buses continue to operate indefinitely.
Input
The input file begins with the number of test cases N. Following this, there are N blocks of information, each corresponding to a test case. The first line of each block contains two integers: D (1 ≤ D ≤ 100) and S (1 ≤ S ≤ 250). Each of the next D lines describes the route of one bus. The first number on each line is M_i, the number of stops on the route, followed by M_i different integers indicating the sequence of stops. The bus begins its route at the first stop listed.
Output
For each test case, output a single line containing 1 if every driver can learn all the news, or 0 if not.