#include "cseslib.hpp"
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>

void failmsg(string msg="") {
    if (msg != "") cerr << msg << endl;
    fail();
}

int main()
{
    int t = read_int(1, 100);
    int ns = 0;
    int mx_n = 0;
    int mx_k = 0;
    int mx_odd = 0;
    int mx_diff = 0;
    for (int tt = 0; tt < t; tt++) {
        auto nk = read_ints(2, 1, 2e5);
        int n = nk[0];
        mx_n = max(mx_n, n);
        ns += n;
        int k_ = nk[1];
        mx_k = max(mx_k, k_);
        if (k_ > n) failmsg("k is larger than n");
        vector<long long> v = read_ints(n, 1, k_);

        map<int, int> mp;
        for (int i : v) {
            mp[i]++;
        }
        vector<int> cnts;
        set<int> cnts_set;
        int odd_c = 0;
        for (auto& p : mp) {
            cnts.push_back(p.second);
            cnts_set.insert(p.second);
            if (p.second % 2 == 1) odd_c++;
        }
        mx_odd = max(mx_odd, odd_c);
        mx_diff = max(mx_diff, (int)cnts_set.size());

        if ((int)cnts.size() != k_) failmsg("all k colors not present");
    }

    if (ns > 2e5) {
        failmsg("sum of n too large");
    }

    vector<int> g;
    if (mx_n <= 3) g.push_back(1);
    if (mx_n <= 15) g.push_back(2);
    if (mx_odd <= 1) g.push_back(3);
    if (mx_diff == 1) g.push_back(4);
    //if (cnts_set.size() <= 2) g.push_back(5);
    if (mx_k <= 15) g.push_back(5);
    g.push_back(6);
    end_groups(g);
}
