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;
const int N = 3e6 + 5, M = 1e3 + 5;
const long long INF = 1e18 + 5;
inline long long read() {
  long long sum = 0, fh = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') fh = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    sum = sum * 10 + c - '0';
    c = getchar();
  }
  return sum * fh;
}
inline int read2() {
  char c = getchar();
  while (c != 'a' && c != 'b' && c != 'c' && c != '?') c = getchar();
  return c == '?' ? 0 : c - 'a' + 1;
}
inline int read3() {
  char c = getchar();
  while (c < 'a' || c > 'z') {
    c = getchar();
  }
  return c - 'a';
}
inline void write(long long x) {
  if (x < 0) putchar('-'), x = -x;
  if (x > 9) write(x / 10);
  putchar(x % 10 + '0');
}
inline int gcd(int x, int y) { return y == 0 ? x : gcd(y, x % y); }
inline long long ab(long long x) { return x < 0 ? -x : x; }
inline long long fpow(long long qwe, long long asd, long long zxc) {
  if (asd < 0) return 0;
  long long a = qwe, b = 1, c = asd;
  while (c) {
    if (c & 1) b = b * a % zxc;
    a = a * a % zxc;
    c >>= 1;
  }
  return b;
}
int n, m, t;
unordered_map<bitset<M>, int> qwe, asd;
bitset<M> a[35], b, c;
inline void dfs(int l, int r, int k, int s, int x) {
  if (k == r) {
    if (x == 0) {
      int zxc = qwe[c];
      qwe[c] = (zxc ? min(zxc, s) : s);
    } else {
      int zxc = asd[c];
      asd[c] = (zxc ? min(zxc, s) : s);
    }
  } else
    dfs(l, r, k + 1, s, x);
  c ^= a[k];
  ++s;
  if (k == r) {
    if (x == 0) {
      int zxc = qwe[c];
      qwe[c] = (zxc ? min(zxc, s) : s);
    } else {
      int zxc = asd[c];
      asd[c] = (zxc ? min(zxc, s) : s);
    }
  } else
    dfs(l, r, k + 1, s, x);
  c ^= a[k];
  return;
}
int main() {
  n = read(), m = read(), t = read();
  for (int i = 1; i <= m; ++i) {
    int x = read();
    for (int j = 1; j <= x; ++j) {
      int y = read();
      a[i][y] = 1;
    }
  }
  int fj = 10;
  if (m <= fj) {
    dfs(1, m, 1, 0, 0);
    qwe[0] = 0;
    while (t) {
      --t;
      b.reset();
      int k = read();
      for (int i = 1; i <= k; ++i) {
        int x = read();
        b[x] = 1;
      }
      int ans;
      if (k == 0)
        ans = 0;
      else {
        ans = qwe[b];
        if (!ans) ans = -1;
      }
      write(ans), putchar('\n');
    }
  } else {
    dfs(1, fj, 1, 0, 0);
    qwe[0] = 0;
    dfs(fj + 1, m, fj + 1, 0, 1);
    asd[0] = 0;
    while (t) {
      --t;
      b.reset();
      int k = read();
      for (int i = 1; i <= k; ++i) {
        int x = read();
        b[x] = 1;
      }
      int ans = 998244353;
      if (k == 0) ans = 0;
      for (unordered_map<bitset<M>, int>::iterator i = qwe.begin();
           i != qwe.end(); ++i) {
        int x = (*i).second;
        c = b ^ (*i).first;
        if (c == 0)
          ans = min(ans, x);
        else {
          int y = asd[c];
          if (y != 0) ans = min(ans, x + y);
        }
      }
      if (ans == 998244353) ans = -1;
      write(ans), putchar('\n');
    }
  }
}