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>
#pragma GCC optimize(2)
using namespace std;
namespace ywy {
inline int get() {
  int n = 0;
  char c;
  while ((c = getchar()) || 23333)
    if (c >= '0' && c <= '9') break;
  n = c - '0';
  while ((c = getchar()) || 233333) {
    if (c >= '0' && c <= '9')
      n = n * 10 + c - '0';
    else
      return (n);
  }
}
typedef struct _bitset {
  unsigned long long data[16];
  _bitset() { memset(data, 0, sizeof(data)); }
  friend _bitset operator^(const _bitset &a, const _bitset &b) {
    _bitset ret;
    for (register int i = 0; i <= 15; i++) ret.data[i] = a.data[i] ^ b.data[i];
    return (ret);
  }
  void set(int bit) { data[bit >> 6] ^= (1ull << (bit & 63)); }
  unsigned long long gen() {
    unsigned long long h1 = 0, h2 = 0;
    for (register int i = 15; i >= 0; i--) {
      unsigned long long x = data[i] % 1000003;
      h1 = (h1 * 1000033 + x) % 998244353;
      h2 = (h2 * 1000033 + x) % 1000000007;
    }
    return ((h1 << 32) | h2);
  }
} bitset;
bitset dts[1024], f[1048576], swit[40];
int cnt[1048576];
unordered_map<unsigned long long, int> mp;
void ywymain() {
  int n = get(), s = get(), d = get();
  for (register int i = 0; i < s; i++) {
    int c = get();
    while (c) c--, swit[i].set(get());
  }
  if (s <= 10) {
    for (register int i = 1; i < (1 << s); i++) {
      for (register int j = 0; j < s; j++) {
        if (i & (1 << j)) {
          dts[i] = dts[i - (1 << j)] ^ swit[j];
          cnt[i] = cnt[i - (1 << j)] + 1;
          break;
        }
      }
    }
  } else {
    for (register int i = 1; i < 1024; i++) {
      for (register int j = 0; j < 10; j++) {
        if (i & (1 << j)) {
          dts[i] = dts[i - (1 << j)] ^ swit[j];
          cnt[i] = cnt[i - (1 << j)] + 1;
          break;
        }
      }
    }
    for (register int i = 1; i < (1 << (s - 10)); i++) {
      for (register int j = 0; j < s - 10; j++) {
        if (i & (1 << j)) {
          f[i] = f[i - (1 << j)] ^ swit[j + 10];
          cnt[i] = cnt[i - (1 << j)] + 1;
          break;
        }
      }
      unsigned long long x = f[i].gen();
      if (!mp.count(x))
        mp[x] = cnt[i];
      else {
        if (cnt[i] < mp[x]) mp[x] = cnt[i];
      }
    }
    mp[0] = 0;
  }
  while (d) {
    d--;
    bitset now;
    int t = get();
    while (t) t--, now.set(get());
    int minn = 123456789;
    if (s <= 10) {
      unsigned long long x = now.gen();
      for (register int i = 0; i < (1 << s); i++) {
        if (dts[i].gen() == x) minn = min(minn, cnt[i]);
      }
    } else {
      for (register int i = 0; i < 1024; i++) {
        unsigned long long x = (dts[i] ^ now).gen();
        if (mp.count(x)) minn = min(minn, cnt[i] + mp[x]);
      }
    }
    if (minn == 123456789)
      printf("-1\n");
    else
      printf("%d\n", minn);
  }
}
}  // namespace ywy
int main() {
  ywy::ywymain();
  return (0);
}