Bundles of Joy

Buy the cheapest set of nested or disjoint bundles that covers every dessert type.

Medium6Dynamic programmingTreeNo attempts yetTime limit3sMemory limit256 MB

Problem

Bob's Bakery has opened. The shop runs a "Bundles of Joy" sale that packs several desserts together so customers taste the whole menu.

For example, the chocolate cake bundle holds a chocolate layer cake and a black forest cake for $20. The fruity cake bundle holds a lemon pound cake and a key lime cake, also for $20. A larger bundle holds one slice of each of those four cakes for $38, which is less than the two smaller bundles together.

You want at least one of every dessert the bakery sells. So you have to buy some bundles, and you want to spend as little as possible.

The bundles have the following properties.

  • For any two bundles AA and BB, every dessert of AA is also in BB, or every dessert of BB is also in AA, or no dessert lies in both.
  • The only way to buy a single dessert on its own is to buy a bundle of size 1. Not every dessert has such a bundle.
  • The prices are not tidy. Buying some combination of other bundles can be cheaper than buying bundle BB itself, even when that combination holds everything in BB.

Input

The first line contains one integer TT, the number of test cases (1T501 \le T \le 50). The first line of each test case contains two integers nn and mm, where nn is the number of dessert types the bakery sells and mm is the number of bundles (1n1001 \le n \le 100, 1m1501 \le m \le 150).

The next mm lines describe the bundles, one per line. Line ii begins with two integers pip_i and sis_i, where pip_i is the price of bundle ii (0<pi1060 < p_i \le 10^6) and sis_i is the number of desserts in it (1sin1 \le s_i \le n). The rest of the line holds sis_i distinct integers between 11 and nn, the desserts included in bundle ii.

Each of the nn desserts appears in at least one bundle.

Output

For each test case, print one line with the minimum cost of buying bundles so that you end up with at least one of every dessert. This value fits in a 32-bit signed integer.