Under construction

Still being built. Things may change

Alternative Accounts

Time limit2sMemory limit512 MB

Summary
Given up to 4 contests and the accounts in each, find the fewest people who can own all accounts, where two accounts in the same contest need different owners.
Level

Medium6 of 10

Topics
Bit manipulation, Graph, Brute force
Solved
No attempts yet

Problem

Everybody knows that jiry_2 = Syloviaely.

There are nn different accounts on the website, and some of them competed in the recent kk contests. Mike suspects that there are many alternative accounts, meaning two or more accounts owned by the same person.

Two axioms are believed by everyone:

  • Nobody can use two different accounts in one contest at the same time.
  • Nobody shares an account. Each account can only be owned by one person.

So, a set of accounts may be owned by the same person if no two of them took part in the same contest.

Mike wants to know the minimum possible number of different people behind the given list of accounts.

Input

The first line contains an integer TT (1≤T≤1051 \le T \le 10^5), the number of test cases. Each test case is described as follows.

The first line contains two integers nn and kk (1≤n≤1051 \le n \le 10^5, 1≤k≤41 \le k \le 4).

Each of the following kk lines starts with an integer mm (1≤m≤n1 \le m \le n), followed by mm distinct integers xix_i (1≤xi≤n1 \le x_i \le n), the accounts that took part in that contest.

Some accounts may not take part in any contest.

It is guaranteed that ∑n≤5×105\sum n \le 5 \times 10^5.

Output

For each test case, print one line with one integer: the answer.

Examples1

  1. Example 1

    Input
    1
    5 3
    2 1 2
    3 2 3 4
    4 4 5 1 2
    
    Expected output
    4