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("O3")
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimize("unroll-loops")
using namespace std;
unordered_map<long long, long long> z1;
const long long cnt = 63;
const long long cnt2 = 16;
long long w[100];
long long has(vector<long long> v) {
  long long ans = 0;
  for (long long i = 0; i < cnt2; ++i) {
    ans += v[i] * w[i];
  }
  return ans;
}
long long po[64];
vector<long long> nv;
vector<long long> go(vector<long long> v) {
  vector<long long> ans;
  for (long long i = 0; i < cnt2; ++i) {
    ans.push_back(0);
  }
  for (auto h : v) {
    h--;
    ans[h / cnt] += po[h % cnt];
  }
  return ans;
}
vector<long long> to(vector<long long> a, vector<long long> b) {
  vector<long long> c(cnt2);
  for (long long i = 0; i < cnt2; ++i) c[i] = a[i] ^ b[i];
  return c;
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  for (long long i = 0; i < 100; ++i) w[i] = rand() * 1e9 + rand();
  long long u1 = 1;
  for (long long i = 0; i < 64; ++i) {
    po[i] = u1;
    u1 *= 2;
  }
  for (long long i = 0; i < cnt2; ++i) nv.push_back(0);
  long long n, s, d;
  cin >> n >> s >> d;
  vector<vector<long long> > v;
  for (long long i = 0; i < s; ++i) {
    long long c;
    cin >> c;
    vector<long long> h(c);
    for (long long i = 0; i < c; ++i) cin >> h[i];
    v.push_back(go(h));
  }
  vector<vector<long long> > v1, v2;
  for (long long i = 0; i < (s / 2); ++i) v1.push_back(v[i]);
  for (long long i = (s / 2); i < s; ++i) v2.push_back(v[i]);
  vector<vector<long long> > l1;
  vector<long long> l0;
  for (long long mask = 0; mask < (1 << v1.size()); ++mask) {
    vector<long long> u = nv;
    for (long long i = 0; i < v1.size(); ++i) {
      if (mask & (1 << i)) {
        u = to(u, v1[i]);
      }
    }
    l1.push_back(u);
    l0.push_back(__builtin_popcount(mask));
  }
  for (long long mask = 0; mask < (1 << v2.size()); ++mask) {
    vector<long long> u = nv;
    for (long long i = 0; i < v2.size(); ++i) {
      if (mask & (1 << i)) {
        u = to(u, v2[i]);
      }
    }
    long long ha = has(u);
    if (z1.count(ha))
      z1[ha] = min(z1[ha], (long long)__builtin_popcount(mask));
    else
      z1[ha] = __builtin_popcount(mask);
  }
  for (long long i = 0; i < d; ++i) {
    long long c;
    cin >> c;
    vector<long long> h(c);
    for (long long i = 0; i < c; ++i) cin >> h[i];
    vector<long long> z = go(h);
    long long ans = 1e18;
    for (long long i = 0; i < l1.size(); ++i) {
      long long has1 = 0;
      for (long long j = 0; j < cnt2; ++j) {
        has1 += (l1[i][j] ^ z[j]) * w[j];
      }
      if (z1.count(has1)) ans = min(ans, z1[has1] + l0[i]);
    }
    if (ans == 1e18)
      cout << (-1) << endl;
    else
      cout << ans << endl;
  }
  return 0;
}