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;
int inf;
const double eps = 1e-8;
const double pi = acos(-1.0);
template <class T, class T2>
int chkmin(T &a, T2 b) {
  return a > b ? a = b, 1 : 0;
}
template <class T, class T2>
int chkmax(T &a, T2 b) {
  return a < b ? a = b, 1 : 0;
}
template <class T>
T sqr(T a) {
  return a * a;
}
template <class T, class T2>
T mmin(T a, T2 b) {
  return a < b ? a : b;
}
template <class T, class T2>
T mmax(T a, T2 b) {
  return a > b ? a : b;
}
template <class T>
T aabs(T a) {
  return a < 0 ? -a : a;
}
template <class T>
int dcmp(T a, T b) {
  return a > b;
}
template <int *a>
int cmp_a(int first, int second) {
  return a[first] < a[second];
}
struct __INIT__ {
  __INIT__() {
    fill((unsigned char *)(&inf), (unsigned char *)(&inf) + sizeof(inf), 0x3f);
  }
} __INIT___;
namespace io {
const int SIZE = (1 << 21) + 1;
char ibuf[SIZE], *iS, *iT, obuf[SIZE], *oS = obuf, *oT = oS + SIZE - 1, c,
                                       qu[55];
int f, qr;
inline void flush() {
  fwrite(obuf, 1, oS - obuf, stdout);
  oS = obuf;
}
inline void putc(char first) {
  *oS++ = first;
  if (oS == oT) flush();
}
template <typename A>
inline bool read(A &first) {
  for (f = 1, c = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, SIZE, stdin),
                              (iS == iT ? EOF : *iS++))
                            : *iS++);
       c < '0' || c > '9';
       c = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, SIZE, stdin),
                       (iS == iT ? EOF : *iS++))
                     : *iS++))
    if (c == '-')
      f = -1;
    else if (c == EOF)
      return 0;
  for (first = 0; c <= '9' && c >= '0';
       c = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, SIZE, stdin),
                       (iS == iT ? EOF : *iS++))
                     : *iS++))
    first = first * 10 + (c & 15);
  first *= f;
  return 1;
}
inline bool read(char &first) {
  while ((first = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, SIZE, stdin),
                               (iS == iT ? EOF : *iS++))
                            : *iS++)) == ' ' ||
         first == '\n' || first == '\r')
    ;
  return first != EOF;
}
inline bool read(char *first) {
  while ((*first = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, SIZE, stdin),
                                (iS == iT ? EOF : *iS++))
                             : *iS++)) == '\n' ||
         *first == ' ' || *first == '\r')
    ;
  if (*first == EOF) return 0;
  while (!(*first == '\n' || *first == ' ' || *first == '\r' || *first == EOF))
    *(++first) = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, SIZE, stdin),
                              (iS == iT ? EOF : *iS++))
                           : *iS++);
  *first = 0;
  return 1;
}
template <typename A, typename... B>
inline bool read(A &first, B &...second) {
  return read(first) && read(second...);
}
template <typename A>
inline bool write(A first) {
  if (!first) putc('0');
  if (first < 0) putc('-'), first = -first;
  while (first) qu[++qr] = first % 10 + '0', first /= 10;
  while (qr) putc(qu[qr--]);
  return 0;
}
inline bool write(char first) {
  putc(first);
  return 0;
}
inline bool write(const char *first) {
  while (*first) {
    putc(*first);
    ++first;
  }
  return 0;
}
inline bool write(char *first) {
  while (*first) {
    putc(*first);
    ++first;
  }
  return 0;
}
template <typename A, typename... B>
inline bool write(A first, B... second) {
  return write(first) || write(second...);
}
struct Flusher_ {
  ~Flusher_() { flush(); }
} io_flusher_;
}  // namespace io
using io ::putc;
using io ::read;
using io ::write;
bitset<1005> l[1005], a, hv;
unsigned w[31], lw[1005];
int k, c, n;
void Insert() {
  unsigned s = 0;
  for (int i = n; i; --i)
    if (a[i]) {
      if (hv[i]) {
        s ^= lw[i];
        a ^= l[i];
      } else {
        s |= 1 << k;
        ++k;
        lw[i] = s;
        l[i] = a;
        hv[i] = 1;
        for (int j = 1; j < i; ++j)
          if (l[i][j]) {
            l[i] ^= l[j];
            lw[i] ^= lw[j];
          }
        for (int j = i + 1; j <= n; ++j)
          if (l[j][i]) {
            l[j] ^= l[i];
            lw[j] ^= lw[i];
          }
        return;
      }
    }
  w[c] = s;
  ++c;
}
int get() {
  unsigned s = 0;
  for (int i = n; i; --i)
    if (a[i]) {
      if (hv[i]) {
        s ^= lw[i];
        a ^= l[i];
      } else
        return -1;
    }
  return s;
}
unsigned v[1 << 15 | 5];
int dis[1 << 15 | 5];
int q[1 << 15 | 5];
void bfs() {
  for (int i = 0; i < (1 << k); ++i) dis[i] = inf;
  int *l = q, *r = q;
  *q = 0;
  dis[0] = 0;
  for (; l <= r; ++l) {
    for (int i = 0; i < c; ++i)
      if (chkmin(dis[*l ^ w[i]], dis[*l] + 1)) {
        *(++r) = *l ^ w[i];
      }
  }
}
signed main() {
  int s, q;
  read(n, s, q);
  for (int i = 1; i <= s; ++i) {
    int m, first;
    read(m);
    a.reset();
    for (int j = 1; j <= m; ++j) {
      read(first);
      a[first] = 1;
    }
    Insert();
  }
  if (k <= 15) {
    bfs();
    for (; q; --q) {
      int m, first;
      read(m);
      a.reset();
      for (int j = 1; j <= m; ++j) {
        read(first);
        a[first] = 1;
      }
      int w = get();
      if (w < 0)
        write("-1\n");
      else {
        int ans = inf;
        for (int j = 0; j < (1 << k); ++j)
          chkmin(ans, __builtin_popcount(j ^ w) + dis[j]);
        write(ans, '\n');
      }
    }
  } else {
    for (int i = 0; i < c; ++i) {
      v[1 << i] = w[i];
    }
    for (int i = 1; i < (1 << c); ++i)
      if (i & (i - 1)) v[i] = v[i & (i - 1)] ^ v[i & (-i)];
    for (; q; --q) {
      int m, first;
      read(m);
      a.reset();
      for (int j = 1; j <= m; ++j) {
        read(first);
        a[first] = 1;
      }
      int w = get();
      if (w < 0)
        write("-1\n");
      else {
        int ans = inf;
        for (int j = 0; j < (1 << c); ++j)
          chkmin(ans, __builtin_popcount(j) + __builtin_popcount(w ^ v[j]));
        write(ans, '\n');
      }
    }
  }
  return 0;
}