#include <bits/stdc++.h>
using namespace std;
inline void read(int &x) {
  int v = 0, f = 1;
  char c = getchar();
  while (!isdigit(c) && c != '-') c = getchar();
  if (c == '-')
    f = -1;
  else
    v = (c & 15);
  while (isdigit(c = getchar())) v = (v << 1) + (v << 3) + (c & 15);
  x = v * f;
}
inline void read(long long &x) {
  long long v = 0ll, f = 1ll;
  char c = getchar();
  while (!isdigit(c) && c != '-') c = getchar();
  if (c == '-')
    f = -1;
  else
    v = (c & 15);
  while (isdigit(c = getchar())) v = (v << 1) + (v << 3) + (c & 15);
  x = v * f;
}
inline void readc(char &x) {
  char c;
  while (((c = getchar()) == ' ') || c == '\n')
    ;
  x = c;
}
int n, m, g, cg, cn, i, j, k, l, ch[105][2], fa[105], ban[105], cnt = 1,
                                                                fr[105];
vector<int> e[105], ef[105];
int lc[105], rc[105];
long long dp[105][105][105];
priority_queue<pair<long long, pair<int, pair<int, int> > >,
               vector<pair<long long, pair<int, pair<int, int> > > >,
               greater<pair<long long, pair<int, pair<int, int> > > > >
    pq;
void upd(int x, int y, int z, long long c) {
  if (c < dp[x][y][z]) {
    dp[x][y][z] = c;
    pq.push(make_pair(c, make_pair(x, make_pair(y, z))));
  }
}
int main() {
  read(g);
  read(n);
  read(m);
  cg = g;
  cn = n;
  for (((i)) = (1); ((i)) <= ((n)); ((i))++) {
    lc[i] = rc[i] = -1;
    int x, y, t;
    read(x);
    read(y);
    e[x].push_back(t = i);
    read(lc[t]);
    y--;
    while (y--) {
      if (y == 0) {
        read(rc[t]);
      } else {
        rc[t] = cg++;
        e[cg - 1].push_back(++cn);
        t = cn;
        read(lc[t]);
        rc[t] = -1;
      }
    }
  }
  for (((i)) = (0); ((i)) <= (((int)(cg)) - 1); ((i))++) {
    for (__typeof((e[i]).begin()) it = (e[i]).begin(); it != (e[i]).end(); it++)
      fr[*it] = i;
  }
  for (((i)) = (1); ((i)) <= ((cn)); ((i))++) {
    ef[lc[i]].push_back(i);
    if (rc[i] != -1 && rc[i] != lc[i]) ef[rc[i]].push_back(i);
  }
  for (((i)) = (1); ((i)) <= ((m)); ((i))++) {
    int x = 1, l;
    read(l);
    while (l--) {
      int t;
      read(t);
      if (!ch[x][t]) ch[x][t] = ++cnt;
      x = ch[x][t];
    }
    ban[x] = 1;
  }
  queue<int> q;
  for (((i)) = (0); ((i)) <= (((int)(2)) - 1); ((i))++)
    if (ch[1][i]) {
      q.push(ch[1][i]);
      fa[ch[1][i]] = 1;
    } else
      ch[1][i] = 1;
  while (!q.empty()) {
    int x = q.front();
    q.pop();
    ban[x] |= ban[fa[x]];
    for (((i)) = (0); ((i)) <= (((int)(2)) - 1); ((i))++)
      if (ch[x][i]) {
        q.push(ch[x][i]);
        fa[ch[x][i]] = ch[fa[x]][i];
      } else
        ch[x][i] = ch[fa[x]][i];
  }
  memset((dp), (0x16), (sizeof((dp))));
  for (((i)) = (1); ((i)) <= ((cnt)); ((i))++) {
    if (!ban[i]) {
      if (!ban[ch[i][0]]) {
        upd(0, i, ch[i][0], 1);
      }
      if (!ban[ch[i][1]]) {
        upd(1, i, ch[i][1], 1);
      }
    }
  }
  while (!pq.empty()) {
    long long v = pq.top().first;
    int x = pq.top().second.first, a = pq.top().second.second.first,
        b = pq.top().second.second.second;
    pq.pop();
    if (dp[x][a][b] != v) continue;
    for (__typeof((ef[x]).begin()) it = (ef[x]).begin(); it != (ef[x]).end();
         it++) {
      if (lc[*it] == x) {
        if (rc[*it] == -1) {
          upd(fr[*it], a, b, v);
          continue;
        }
        for (((i)) = (1); ((i)) <= ((cnt)); ((i))++) {
          upd(fr[*it], a, i, v + dp[rc[*it]][b][i]);
        }
      }
      if (rc[*it] == x) {
        for (((i)) = (1); ((i)) <= ((cnt)); ((i))++) {
          upd(fr[*it], i, b, v + dp[lc[*it]][i][a]);
        }
      }
    }
  }
  for ((i) = (2); (i) <= (g - 1); (i)++) {
    long long ans = dp[104][104][104];
    for (((j)) = (1); ((j)) <= ((cnt)); ((j))++)
      if (!ban[j]) ans = min(ans, dp[i][1][j]);
    if (ans >= dp[104][104][104]) {
      puts("YES");
    } else {
      printf("NO %lld\n", ans);
    }
  }
  return 0;
}
