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;
namespace io {
const int BUFSIZE = 1 << 20;
char ibuf[BUFSIZE], *is = ibuf, *it = ibuf;
char obuf[BUFSIZE], *os = obuf, *ot = obuf + BUFSIZE - 1;
inline void read_char(char &c) {
  if (is == it) {
    it = (is = ibuf) + fread(ibuf, 1, BUFSIZE, stdin);
    if (is == it) *it++ = EOF;
  }
  c = *is++;
}
template <class T>
inline void read_int(T &x) {
  T f = 1;
  char c;
  read_char(c);
  while (!isdigit(c)) {
    if (c == '-') {
      f = -1;
    }
    read_char(c);
  }
  x = 0;
  while (isdigit(c)) {
    x = x * 10 + c - '0';
    read_char(c);
  }
  x *= f;
}
inline void flush() {
  fwrite(obuf, 1, os - obuf, stdout);
  os = obuf;
}
inline void print_char(char c) {
  *os++ = c;
  if (os == ot) {
    flush();
  }
}
template <class T>
inline void print_int(T x) {
  static char q[40];
  if (!x) {
    print_char('0');
  } else {
    if (x < 0) {
      print_char('-');
      x = -x;
    }
    int top = 0;
    while (x) {
      q[top++] = x % 10 + '0';
      x /= 10;
    }
    while (top--) {
      print_char(q[top]);
    }
  }
}
struct flusher_t {
  inline ~flusher_t() { flush(); }
} flusher;
}  // namespace io
using io::print_char;
using io::print_int;
using io::read_char;
using io::read_int;
const int N = 1005;
const int mod = 998244353;
int wei[16];
struct Bitset {
  unsigned long long a[16];
  inline Bitset() { memset(a, 0, sizeof(a)); }
  inline void reset() { memset(a, 0, sizeof(a)); }
  inline void set(int i) { a[i >> 6] |= (1ull << (i & 63)); }
  inline Bitset &operator^=(const Bitset &oth) {
    for (int i = 0; i < 16; i++) a[i] ^= oth.a[i];
    return *this;
  }
  inline Bitset operator^(const Bitset &oth) const {
    Bitset ret;
    for (int i = 0; i < 16; i++) ret.a[i] = a[i] ^ oth.a[i];
    return ret;
  }
  inline int getval() const {
    unsigned long long ret = 0;
    for (int i = 0; i < 16; i++) {
      ret = (ret + a[i] % mod * wei[i]) % mod;
    }
    return ret;
  }
  inline bool operator==(const Bitset &oth) const {
    for (int i = 0; i < 16; i++)
      if (a[i] != oth.a[i]) return false;
    return true;
  }
};
int n, s, s1, s2, d;
Bitset c[35], l1[1 << 20], cur, tmp;
inline void getmin(int &x, int y) {
  if (x > y) x = y;
}
namespace HT {
int head[1145141], to[(1 << 20) + 5], nxt[(1 << 20) + 5], tot;
Bitset ts[(1 << 20) + 5];
inline void Add(const Bitset &bs, int toto) {
  int val = bs.getval() % 1145141;
  for (int i = head[val]; i; i = nxt[i]) {
    if (ts[i] == bs) {
      to[i] = min(to[i], toto);
      return;
    }
  }
  ++tot;
  to[tot] = toto;
  nxt[tot] = head[val];
  ts[tot] = bs;
  head[val] = tot;
}
inline int Query(const Bitset &bs) {
  int val = bs.getval() % 1145141;
  for (int i = head[val]; i; i = nxt[i]) {
    if (ts[i] == bs) {
      return to[i];
    }
  }
  return 114;
}
}  // namespace HT
int main() {
  mt19937 rng(1145141);
  for (int i = 0; i < 16; i++)
    wei[i] = uniform_int_distribution<int>(1, mod - 1)(rng);
  read_int(n);
  read_int(s);
  read_int(d);
  for (int i = 0; i < s; i++) {
    int sz;
    read_int(sz);
    while (sz--) {
      int x;
      read_int(x);
      c[i].set(x);
    }
  }
  s1 = min(s / 2, 10);
  s2 = s - s1;
  for (int mask = 0; mask < (1 << s1); mask++) {
    cur.reset();
    for (int i = 0; i < s1; i++)
      if (mask >> i & 1) {
        cur ^= c[i];
      }
    l1[mask] = cur;
  }
  for (int mask = 0; mask < (1 << s2); mask++) {
    cur.reset();
    for (int i = s1; i < s; i++)
      if (mask >> (i - s1) & 1) {
        cur ^= c[i];
      }
    HT::Add(cur, __builtin_popcount(mask));
  }
  while (d--) {
    cur.reset();
    int sz;
    read_int(sz);
    while (sz--) {
      int x;
      read_int(x);
      cur.set(x);
    }
    int ans = 114;
    for (int mask = 0; mask < (1 << s1); mask++) {
      tmp = cur ^ l1[mask];
      ans = min(ans, __builtin_popcount(mask) + HT::Query(tmp));
    }
    if (ans == 114) ans = -1;
    print_int(ans);
    print_char('\n');
  }
  return 0;
}