#include <bits/stdc++.h>
using namespace std;
const unsigned long long inf = (1ull << 63);
const int N = 210, M = 60;
int n, m, cnt, tot, ch[M][2], Q[M], fail[M];
bool ok[M];
vector<pair<int, int> > G[N];
unsigned long long dp[N][M][M];
struct node {
  int u, x, y;
  unsigned long long d;
  node(int _u = 0, int _x = 0, int _y = 0, unsigned long long _d = 0)
      : u(_u), x(_x), y(_y), d(_d) {}
};
inline bool operator<(node a, node b) { return a.d > b.d; }
priority_queue<node> q;
void ins(int n) {
  int o = 1;
  for (int i = (1); i <= (n); ++i) {
    int x;
    scanf("%d", &x);
    if (!ch[o][x]) ch[o][x] = ++cnt;
    o = ch[o][x];
  }
  ok[o] = 1;
}
void construct() {
  int *s = Q, *e = Q;
  for (int i = (0); i <= (1); ++i)
    ch[1][i] ? (*s++ = ch[1][i], fail[ch[1][i]] = 1) : ch[1][i] = 1;
  while (s != e) {
    int u = *e++;
    ok[u] |= ok[fail[u]];
    for (int i = (0); i <= (1); ++i)
      ch[u][i] ? (*s++ = ch[u][i], fail[ch[u][i]] = ch[fail[u]][i])
               : (ch[u][i] = ch[fail[u]][i]);
  }
}
inline void upd(int u, int x, int y, unsigned long long d) {
  if (dp[u][x][y] > d) dp[u][x][y] = d, q.emplace(u, x, y, d);
}
int main() {
  int zz;
  scanf("%d%d%d", &n, &zz, &m);
  cnt = 1;
  tot = --n;
  for (int i = (1); i <= (zz); ++i) {
    int x, l, y;
    scanf("%d%d", &x, &l);
    for (int j = (1); j <= (l - 1); ++j)
      scanf("%d", &y), G[tot + j + 1].emplace_back(tot + j, y),
          G[y].emplace_back(tot + j, tot + j + 1);
    scanf("%d", &y), G[y].emplace_back(tot + l, -1);
    G[tot + 1].emplace_back(x, -1);
    tot += l;
  }
  for (int i = (1); i <= (m); ++i) {
    int l;
    scanf("%d", &l);
    ins(l);
  }
  construct();
  for (int t = (0); t <= (tot); ++t)
    for (int i = (1); i <= (cnt); ++i)
      for (int j = (1); j <= (cnt); ++j) dp[t][i][j] = inf;
  for (int i = (0); i <= (1); ++i)
    for (int j = (1); j <= (cnt); ++j)
      if (!ok[j] && !ok[ch[j][i]]) upd(i, j, ch[j][i], 1);
  while (!q.empty()) {
    auto [u, x, y, d] = q.top();
    q.pop();
    if (dp[u][x][y] != d) continue;
    for (auto &[v, w] : G[u]) {
      if (w == -1)
        upd(v, x, y, d);
      else if (u <= n) {
        for (int z = (1); z <= (cnt); ++z)
          if (!ok[z]) upd(v, x, z, d + dp[w][y][z]);
      } else {
        for (int z = (1); z <= (cnt); ++z)
          if (!ok[z]) upd(v, z, y, d + dp[w][z][x]);
      }
    }
  }
  for (int i = (2); i <= (n); ++i) {
    unsigned long long ans = inf;
    for (int j = (1); j <= (cnt); ++j) ans = min(ans, dp[i][1][j]);
    ans == inf ? puts("YES") : printf("NO %llu\n", ans);
  }
  return 0;
}
