import java.util.*;
public class Q31 {
  public static void main(String[] args) {
    Scanner in = new Scanner(System.in);
    int numCase = in.nextInt();
    for(int cs = 0; cs < numCase; cs++) {
      int n = in.nextInt();
      int p = in.nextInt();
      in.nextLine();

      int[] packBit = new int[p];   // bitmask of what is in the package
      int[] packPrice = new int[p]; // price of the package

      // read packages
      for(int i = 0; i < p; i++) {
        String line = in.nextLine();
        String[] toks = line.trim().split(" +");
        packPrice[i] = Integer.parseInt(toks[0]);
        for(int j = 1; j < toks.length; j++)
          packBit[i] |= (1 << Integer.parseInt(toks[j]));
      }

      // do DP on what is bought (bitmask)
      int[] dp = new int[1 << n];

      // base case is when all is bought, bitmask = (1 << n) -1
      // cost is already initilized to 0
      for(int i = (1 << n) - 2; i >= 0; i--) {
        dp[i] = Integer.MAX_VALUE / 1000;
        for(int pack = 0; pack < p; pack++)
          dp[i] = Math.min(dp[i], dp[i | packBit[pack]] + packPrice[pack]);
      }

      System.out.println(dp[0]);
    }
  }
}
