#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9;
unordered_map<bitset<1005>, int> table;
bitset<1005> empty, swi[40];
int s, d, jk;
void init() {
  int add = min(20, s);
  bitset<1005> tmp;
  for (int mask = (0), maskend = ((1 << add) - 1); mask <= maskend; mask++) {
    int cnt = 0;
    tmp.reset();
    for (int j = (1), jend = (add); j <= jend; j++) {
      if (mask & (1 << (j - 1))) {
        cnt++;
        tmp ^= swi[j];
      }
    }
    int val = table[tmp];
    if (!val || val > cnt) table[tmp] = cnt;
  }
}
int main() {
  scanf("%d%d%d", &jk, &s, &d);
  for (int i = (1), iend = (s); i <= iend; i++) {
    int num;
    scanf("%d", &num);
    for (int j = (1), jend = (num); j <= jend; j++) {
      int val;
      scanf("%d", &val);
      swi[i][val] = 1;
    }
  }
  init();
  bitset<1005> tmp, now;
  for (int i = (1), iend = (d); i <= iend; i++) {
    tmp.reset();
    int t;
    scanf("%d", &t);
    for (int j = (1), jend = (t); j <= jend; j++) {
      int num;
      scanf("%d", &num);
      tmp[num] = 1;
    }
    if (tmp == empty) {
      printf("0\n");
      continue;
    }
    if (s <= 20) {
      int val = table[tmp];
      if (!val) val = -1;
      printf("%d\n", val);
    } else {
      int add = s - 20;
      int ans = inf;
      for (int mask = (0), maskend = ((1 << add) - 1); mask <= maskend;
           mask++) {
        int cnt = 0;
        now = tmp;
        for (int j = (1), jend = (add); j <= jend; j++)
          if (mask & (1 << (j - 1))) cnt++, now ^= swi[j + 20];
        if (empty == now) {
          ans = min(ans, cnt);
          continue;
        }
        int val = table[now];
        if (val) ans = min(ans, val + cnt);
      }
      if (ans == inf) ans = -1;
      printf("%d\n", ans);
    }
  }
  return 0;
}
