This page is still under construction.

Parts of this page are still being built. What you see may change.

Going to the Movies

Time limit2sMemory limit128 MB

Summary
Given M movies each covering a subset of P preferences, find the smallest number of movies whose coverage includes all P preferences.
Level

Medium5 of 10

Topics
Bit manipulation, Brute force, Greedy, Implementation
Solved
No attempts yet

Problem

Alan Turing and Edsger Dijkstra rarely get the chance to go to the movies. Being European, cinema is more of an American tradition to them, so on their infrequent visits to the States they gather with their colleagues every weekend and stay glued to the big screen until Monday. Finding a quick route to the theater is easy; agreeing on what to watch is not. Their tastes differ wildly. Turing, for instance, loves romance films, while Dijkstra can't stand them, which makes choosing movies extremely difficult. They refuse to split up and watch different titles alone, because then there would be no point in getting together as a group: they could not even discuss what they saw, since not everyone would have seen the same films.

To solve this, they devised a scheme to minimize the number of films they must watch while still satisfying every member. They aggregate everyone's tastes into a master list of preferences such as "romance", "action", and "horror". For each candidate movie they determine which preferences on the list it satisfies. All that is left is to find the smallest set of movies that together satisfy every preference on the list. That is where you come in.

Input

The first line contains the number KK of data sets. The KK data sets follow, each in the form below.

The first line of a data set contains two integers MM and PP: the number of movies and the number of preferences on the list, with 1≤M≤301 \le M \le 30 and 1≤P≤201 \le P \le 20. The next MM lines describe the movies; the ii-th of these lines lists the preferences that movie ii satisfies, given as between 11 and PP integers in the range 11 to PP.

Output

For each data set, print "Data Set x:" on a line by itself, where xx is the data set's number, starting from 11. On the next line, print the minimum number of movies needed to satisfy every preference. If the preferences cannot all be satisfied, print "Impossible" instead. Separate consecutive data sets with a blank line.

Examples3

  1. Example 1

    Input
    2
    4 3
    1 2
    1 3
    2 3
    1
    1 2
    1
    
    Expected output
    Data Set 1:
    2
    
    Data Set 2:
    Impossible
    
  2. Example 2

    Input
    1
    1 3
    1 2 3
    
    Expected output
    Data Set 1:
    1
    
  3. Example 3

    Input
    1
    1 2
    1
    
    Expected output
    Data Set 1:
    Impossible