// grader.cpp (always prints two numbers; protocol violation => x = -1)
#include <bits/stdc++.h>
using namespace std;

static const string GRADER_SECRET = "7K4t9P2xL1m8Q5r";

extern int solve(int N);

// ---- Problem limits ----
static const int MINN = 6;
static const int MAXN = 1000;
static const int MAX_QUERY = 3000;

// ---- Internal state ----
static int gN;
static long long gK;
static long long gOutX = -1; // will be set on normal answer
static long long gOutQ = 0;
static int gQueryCnt = 0;

// recipes: (a,b,c) with c=-1 for pairs
static vector<array<int,3>> gRecipes;
static vector<int> inY;
static int curStamp = 1;

static inline int limitY(int N) {
    return (N + 1) / 2 + 1; // ceil(N/2 + 1)
}

static void die_proto() {
    // Protocol violation => output sentinel (-1) and current query count, then exit.
    gOutX = -1;
    gOutQ = gQueryCnt;
    cout << GRADER_SECRET << "\n";
    cout << gOutX << "\n" << gOutQ << "\n";
    exit(0);
}

extern int query(std::vector<int> Y) {
    gQueryCnt++;
    if (gQueryCnt > MAX_QUERY) die_proto();

    int L = (int)Y.size();
    if (L < 0 || L > limitY(gN)) die_proto();

    sort(Y.begin(), Y.end());
    for (int i = 0; i < L; i++) {
        if (Y[i] < 0 || Y[i] >= gN) die_proto();
        if (i && Y[i] == Y[i-1]) die_proto();
    }

    // stamp mark
    curStamp++;
    if (curStamp == INT_MAX) {
        curStamp = 1;
        fill(inY.begin(), inY.end(), 0);
    }
    for (int v : Y) inY[v] = curStamp;

    long long cnt = 0;
    for (auto &rec : gRecipes) {
        int a = rec[0], b = rec[1], c = rec[2];
        if (inY[a] != curStamp) continue;
        if (inY[b] != curStamp) continue;
        if (c != -1 && inY[c] != curStamp) continue;
        cnt++;
    }

    if (cnt > INT_MAX) die_proto();
    return (int)cnt;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int gtc;
    cin >> gtc;

    cin >> gN;
    if (!cin) return 0;
    if (gN < MINN || gN > MAXN) return 0;

    cin >> gK;
    if (!cin) return 0;
    if (gK < 0) return 0;

    inY.assign(gN, 0);
    gRecipes.reserve((size_t)gK);

    for (long long i = 0; i < gK; i++) {
        int L; cin >> L;
        vector<int> a(L);
        for (int j = 0; j < L; j++) cin >> a[j];
        if (!cin) return 0;

        sort(a.begin(), a.end());
        if (!(L == 2 || L == 3)) return 0;
        for (int j = 0; j < L; j++) if (a[j] < 0 || a[j] >= gN) return 0;
        for (int j = 1; j < L; j++) if (a[j] == a[j-1]) return 0;

        if (L == 2) gRecipes.push_back({a[0], a[1], -1});
        else gRecipes.push_back({a[0], a[1], a[2]});
    }

    gOutX = solve(gN);
    gOutQ = gQueryCnt;
    cout << GRADER_SECRET << "\n";
    cout << gOutX << "\n" << gOutQ << "\n";
    return 0;
}
