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("Ofast,unroll-loops")
#pragma GCC target("avx,avx2,fma")
using namespace std;
using ld = long double;
using ll = int64_t;
using pii = pair<int, int>;
using ull = uint64_t;
struct Bitset {
  uint64_t bs[16];
  Bitset() { memset(bs, 0, sizeof bs); }
  void set(int idx) { bs[idx / 64] |= (1ull << (idx % 64)); }
  Bitset& operator^=(const Bitset& rhs) {
    for (int i = 0; i < 16; ++i) {
      bs[i] ^= rhs.bs[i];
    }
    return *this;
  }
  ull hash() const {
    ull ans = 0x712673081AAAAAFFull;
    for (int i = 0; i < 16; ++i) {
      ans ^= bs[i] + 0x9e3779b99e3779b9ull + (ans << 6) + (ans >> 2);
    }
    return ans;
  }
} b[30], calc[2][1 << 15];
int popcnt[1 << 15];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  for (int i = 0; i < (1 << 15); ++i) popcnt[i] = __builtin_popcount(i);
  int n, s, d;
  cin >> n >> s >> d;
  for (int i = 0; i < s; ++i) {
    Bitset cur;
    int cnt, x;
    cin >> cnt;
    for (int i = 0; i < cnt; ++i) {
      cin >> x;
      --x;
      cur.set(x);
    }
    b[i] = cur;
  }
  for (int z = 0; z < 2; ++z) {
    for (int mask = (1 << 15); mask--;) {
      Bitset cur;
      int popcnt = 0;
      for (int i = 0; i < 15; ++i) {
        if ((mask >> i) & 1) {
          ++popcnt;
          cur ^= b[z * 15 + i];
        }
      }
      calc[z][mask] = cur;
    }
  }
  unordered_map<ull, int> mp;
  for (int mask = (1 << 15); mask--;) {
    int& rf = mp[calc[1][mask].hash()];
    if (rf == 0) rf = 1e9;
    rf = min(rf, popcnt[mask]);
  }
  while (d--) {
    Bitset cur;
    int cnt, x;
    cin >> cnt;
    for (int i = 0; i < cnt; ++i) {
      cin >> x;
      --x;
      cur.set(x);
    }
    int ans = 1e9;
    for (int i = 0; i < (1 << 15); ++i) {
      if (popcnt[i] >= ans) {
        continue;
      }
      Bitset tst = cur;
      tst ^= calc[0][i];
      ull hsh = tst.hash();
      auto it = mp.find(hsh);
      if (it != mp.end()) {
        ans = min(ans, popcnt[i] + it->second);
      }
    }
    if (ans == (int)1e9) ans = -1;
    cout << ans << '\n';
  }
}