#include <bits/stdc++.h>
using namespace std;
const int mxn = 102;
int n, m, k, u = 1, w = 1;
int a[mxn], lk[mxn];
int b[mxn][mxn], g[mxn][mxn], tr[mxn][2];
long long first[mxn][mxn][mxn], dp[mxn][mxn][mxn];
queue<int> q;
priority_queue<array<long long, 4>, vector<array<long long, 4>>,
               greater<array<long long, 4>>>
    pq;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> m >> k;
  for (int i = 0; i < m; i++) {
    int x, y, z = 0;
    cin >> x >> y;
    for (int j = 0; j < y; j++) {
      int e;
      cin >> e;
      if (!g[z][e]) g[z][e] = u++;
      z = g[z][e];
    }
    b[z][x] = 1;
  }
  for (int i = 0; i < k; i++) {
    int x, z = 0;
    cin >> x;
    for (int j = 0; j < x; j++) {
      int y;
      cin >> y;
      if (!tr[z][y]) tr[z][y] = w++;
      z = tr[z][y];
    }
    a[z] = 1;
  }
  memset(first, 0x3f, sizeof(first));
  q.push(0);
  while (!q.empty()) {
    int c = q.front();
    q.pop();
    for (int i = 0; i < 2; i++) {
      int &x = tr[c][i], y = c ? tr[lk[c]][i] : 0;
      if (x)
        lk[x] = y, q.push(x);
      else
        x = y;
      if (!a[tr[0][i]] && !a[c] && !a[x]) first[i][c][x] = 1;
    }
  }
  memset(dp, 0x3f, sizeof(dp));
  for (int i = 0; i < w; i++)
    if (!a[i]) pq.push({dp[0][i][i] = 0, 0, i, i});
  while (!pq.empty()) {
    long long c = pq.top()[1], x = pq.top()[2], y = pq.top()[3],
              d = pq.top()[0];
    pq.pop();
    if (d != dp[c][x][y]) continue;
    for (int i = 0; i < n; i++)
      if (b[c][i] && first[i][x][y] > d) {
        first[i][x][y] = d;
        for (int j = 0, z; j < u; j++)
          if (z = g[j][i])
            for (int l = 0; l < w; l++) {
              if (dp[z][l][y] > dp[j][l][x] + d) {
                pq.push({dp[z][l][y] = dp[j][l][x] + d, z, l, y});
              }
            }
      }
    for (int i = 0, z; i < n; i++)
      if (z = g[c][i])
        for (int j = 0; j < w; j++) {
          if (dp[z][x][j] > d + first[i][y][j]) {
            pq.push({dp[z][x][j] = d + first[i][y][j], z, x, j});
          }
        }
  }
  for (int i = 2; i < n; i++) {
    long long ret = *min_element(first[i][0], first[i][0] + w);
    if (ret < 0x3f3f3f3f3f3f3f3f)
      cout << "NO " << ret << '\n';
    else
      cout << "YES" << '\n';
  }
  return 0;
}
