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>
using namespace std;
template <typename T>
void chmin(T &x, const T &y) {
  if (x > y) x = y;
}
template <typename T>
void chmax(T &x, const T &y) {
  if (x < y) x = y;
}
int read() {
  char c;
  while ((c = getchar()) < '-')
    ;
  if (c == '-') {
    int x = (c = getchar()) - '0';
    while ((c = getchar()) >= '0') x = x * 10 + c - '0';
    return -x;
  }
  int x = c - '0';
  while ((c = getchar()) >= '0') x = x * 10 + c - '0';
  return x;
}
const int N = 1e3 + 5, S = 30 + 2, B = 15, U = 1 << 15;
struct P {
  bitset<N> a;
  int first_1;
  uint32_t s;
};
vector<P> a;
vector<uint32_t> a0;
int n, s, m;
int upd(bitset<N> &now, uint32_t &s) {
  for (int i = n; i >= 1; --i)
    if (now[i]) {
      for (const auto &x : a)
        if (x.first_1 == i) {
          now ^= x.a;
          s ^= x.s;
          break;
        }
      if (now[i]) return i;
    }
  return 0;
}
int upd2(bitset<N> &now, uint32_t &s) {
  int sz = a.size();
  for (int i = n; i >= 1; --i)
    if (now[i]) {
      for (int j = 0; j <= sz - 1; ++j)
        if (a[j].first_1 == i) {
          now ^= a[j].a;
          s ^= 1 << j;
          break;
        }
      if (now[i]) return i;
    }
  return 0;
}
bitset<N> read_bitset() {
  bitset<N> now;
  int c = read();
  for (int tmp = 1; tmp <= c; ++tmp) now[read()].flip();
  return now;
}
namespace SMALL_A0 {
uint32_t xor_sum[U];
void work() {
  int sz = a0.size();
  int u = (1 << sz) - 1;
  for (int s = 0; s <= u; ++s)
    for (int i = 0; i <= sz - 1; ++i)
      if (s & (1 << i)) xor_sum[s] ^= a0[i];
  for (int tmp = 1; tmp <= m; ++tmp) {
    bitset<N> now = read_bitset();
    uint32_t s_now = 0;
    int j = upd(now, s_now);
    if (j)
      puts("-1");
    else {
      int ans = __builtin_popcount(s_now);
      for (int s = 0; s <= u; ++s)
        chmin(ans, __builtin_popcount(s_now ^ xor_sum[s]));
      printf("%d\n", ans);
    }
  }
}
};  // namespace SMALL_A0
namespace SMALL_A {
int a_sum[S], mn[2][U];
void init(int mn[U], int l, int r) {
  r = r - l + 1;
  int u = (1 << r) - 1;
  for (int s = 0; s <= u; ++s) {
    int xor_a_sum = 0;
    for (int i = 0; i <= r - 1; ++i)
      if ((s >> i) & 1) xor_a_sum ^= a_sum[l + i];
    chmin(mn[xor_a_sum], __builtin_popcount(s));
  }
}
void work() {
  int sz = a.size();
  for (int i = 0; i <= sz - 1; ++i)
    for (int j = 0; j <= s - 1; ++j)
      if (a[i].s & (1 << j)) a_sum[j] ^= 1 << i;
  int u = (1 << sz) - 1;
  for (int i = 0; i <= u; ++i) mn[0][i] = mn[1][i] = s;
  int b = s / 2;
  init(mn[0], 0, b - 1);
  init(mn[1], b, s - 1);
  for (int tmp = 1; tmp <= m; ++tmp) {
    bitset<N> now = read_bitset();
    uint32_t s_now = 0;
    int j = upd2(now, s_now);
    if (j)
      puts("-1");
    else {
      int ans = __builtin_popcount(s_now);
      for (int s0 = 0; s0 <= u; ++s0) chmin(ans, mn[0][s0] + mn[1][s_now ^ s0]);
      printf("%d\n", ans);
    }
  }
}
};  // namespace SMALL_A
int main() {
  cin >> n >> s >> m;
  for (int i = 0; i <= s - 1; ++i) {
    bitset<N> now = read_bitset();
    uint32_t s_now = 1 << i;
    int j = upd(now, s_now);
    if (!j)
      a0.push_back(s_now);
    else
      a.push_back({now, j, s_now});
  }
  if (a0.size() <= 15)
    SMALL_A0::work();
  else
    SMALL_A::work();
}