Problem: Nikola owns a large warehouse which is illuminated by N light bulbs, numbered 1 to N. At the exit of the warehouse, there are S light switches, numbered 1 to S. Each switch swaps the on/off state for some light bulbs, so if a light bulb is off, flipping the switch turns it on, and if the light bulb is on, flipping the switch turns it off.

At the end of the day, Nikola wants to turn all the lights off. To achieve this, he will flip some of the light switches at the exit of the warehouse, but since Nikola is lazy, he wants to flip the _minimum_ number of switches required to turn all the lights off. Since Nikola was not able to calculate the minimum number of switches, he asked you to help him. During a period of D days, Nikola noted which light bulbs were off and which were on at the end of each day. He wants you to tell him the minimum number of switches he needed to flip to turn all the lights off for each of the D days or tell him that it's impossible.

Input

First line contains three integers, N, S and D (1 ≤ N ≤ 10^3, 1 ≤ S ≤ 30, 1 ≤ D ≤ 10^3) – representing number of light bulbs, the number of light switches, and the number of days respectively.

The next S lines contain the description of each light switch as follows: The first number in the line, C_i (1 ≤ C_i ≤ N), represents the number of light bulbs for which the on/off state is swapped by light switch i, the next C_i numbers (sorted in increasing order) represent the indices of those light bulbs.

The next D lines contain the description of light bulbs for each day as follows: The first number in the line, T_i (1 ≤ T_i ≤ N), represents the number of light bulbs which are on at the end of day i, the next T_i numbers (sorted in increasing order) represent the indices of those light bulbs.

Output

Print D lines, one for each day. In the i^{th} line, print the minimum number of switches that need to be flipped on day i, or -1 if it's impossible to turn all the lights off.

Example

Input


4 3 4
2 1 2
2 2 3
1 2
1 1
2 1 3
3 1 2 3
3 1 2 4


Output


2
2
3
-1

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
std::mt19937 rng(
    (int)std::chrono::steady_clock::now().time_since_epoch().count());
const int ms = 1100;
std::bitset<ms> mat[ms];
int read(int n) {
  int size;
  std::cin >> size;
  std::bitset<ms> cur;
  while (size--) {
    int x;
    std::cin >> x;
    cur[x - 1] = true;
  }
  for (int i = 0; i < n; i++) {
    if (!cur[i]) continue;
    if (!mat[i][i]) return -1;
    cur ^= mat[i];
  }
  int ans = 0;
  for (int i = 0; i < 30; i++) {
    if (cur[n + i]) {
      ans ^= 1 << i;
    }
  }
  return ans;
}
int bits[1 << 16];
int pop(int x) {
  return x < (1 << 16) ? bits[x] : bits[x & ((1 << 16) - 1)] + pop(x >> 16);
}
void solve1(int n, int q, std::vector<int> basis) {
  std::vector<int> mask(1, 0);
  for (int i = 0; i < (int)basis.size(); i++) {
    for (int j = 0; j < (1 << i); j++) {
      mask.push_back(mask[j] ^ basis[i]);
    }
  }
  while (q--) {
    int got = read(n);
    if (got == -1) {
      std::cout << "-1\n";
      continue;
    }
    int ans = 1e9;
    for (auto m : mask) {
      ans = std::min(ans, pop(got ^ m));
    }
    std::cout << ans << '\n';
  }
}
void solve2(int n, int q, std::vector<int> basis) {
  int id = 0;
  std::vector<int> mapping;
  for (auto m : basis) {
    while ((m & (1 << id)) == 0) {
      mapping.push_back(id++);
    }
    id++;
  }
  while (id < 30) {
    mapping.push_back(id++);
  }
  assert((int)mapping.size() <= 15);
  std::vector<int> dp(1 << mapping.size(), 1e9), wtf(1 << mapping.size(), 0);
  dp[0] = 0;
  for (int i = 0; i < (1 << (int)mapping.size()); i++) {
    for (int j = 0; j < (int)mapping.size(); j++) {
      if (i & (1 << j)) {
        wtf[i] ^= 1 << mapping[j];
      }
    }
  }
  for (auto mask : basis) {
    for (int i = 0; i < (int)dp.size(); i++) {
      dp[i ^ mask] = std::min(dp[i ^ mask], dp[i] + 1);
    }
  }
  while (q--) {
    int got = read(n);
    if (got == -1) {
      std::cout << "-1\n";
      continue;
    }
    int ans = 1e9;
    for (int i = 0; i < (int)dp.size(); i++) {
      ans = std::min(ans, dp[i] + pop(got ^ wtf[i]));
    }
    std::cout << ans << '\n';
  }
}
int main() {
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(NULL);
  for (int i = 1; i < (1 << 16); i++) {
    bits[i] = (i & 1) + bits[i / 2];
  }
  int n, s, d;
  std::cin >> n >> s >> d;
  for (int ii = 0; ii < s; ii++) {
    std::bitset<ms> cur;
    int size;
    std::cin >> size;
    while (size--) {
      int x;
      std::cin >> x;
      cur[x - 1] = true;
    }
    cur[n + ii] = true;
    for (int i = 0; i < n + s; i++) {
      if (!cur[i]) continue;
      if (mat[i][i]) {
        cur ^= mat[i];
      } else {
        mat[i] = cur;
        for (int j = 0; j < i; j++) {
          if (mat[j][i]) {
            mat[j] ^= cur;
          }
        }
        break;
      }
    }
  }
  std::vector<int> basis;
  for (int i = 0; i < s; i++) {
    int cur = 0;
    for (int j = 0; j < s; j++) {
      if (mat[n + i][n + j]) {
        cur ^= 1 << j;
      }
    }
    if (cur) basis.push_back(cur);
  }
  if ((int)basis.size() <= 15) {
    solve1(n, d, basis);
  } else {
    solve2(n, d, basis);
  }
}