#include <bits/stdc++.h>
using namespace std;
int n, m, k;
int x[1005], y[1005], fa[2][1005], hr[2][1005], kr[2][1005];
map<string, int> M;
char name[20];
int find(int typ, int now) {
  return (fa[typ][now] == now || !fa[typ][now])
             ? now
             : fa[typ][now] = find(typ, fa[typ][now]);
}
int main() {
  int u, v;
  scanf("%d%d%d", &n, &m, &k);
  for (int i = 1; i <= m; i++) scanf("%d%d", &x[i], &y[i]);
  for (int i = 1; i <= k; i++) {
    scanf("%s %d", name, &hr[0][i]);
    M[name] = i;
    scanf("%d", &u);
    for (; u--;) {
      scanf("%d", &v);
      kr[0][v] = hr[0][i];
    }
  }
  for (int i = 1; i <= 2 * n; i++)
    for (int j = 1; j <= m; j++)
      if (find(0, x[j]) != find(0, y[j]) &&
          (find(0, kr[0][j]) == find(0, x[j]) ||
           find(0, kr[0][j]) == find(0, y[j])))
        fa[0][find(0, x[j])] = find(0, y[j]);
  for (int i = 1, now; i <= k; i++) {
    scanf("%s", name);
    now = M[name];
    scanf("%d", &hr[1][now]);
    scanf("%d", &u);
    for (; u--;) {
      scanf("%d", &v);
      kr[1][v] = hr[1][now];
    }
  }
  for (int i = 1; i <= 2 * n; i++)
    for (int j = 1; j <= m; j++)
      if (find(1, x[j]) != find(1, y[j]) &&
          (find(1, kr[1][j]) == find(1, x[j]) ||
           find(1, kr[1][j]) == find(1, y[j])))
        fa[1][find(1, x[j])] = find(1, y[j]);
  for (int i = 1; i <= m; i++)
    if (find(0, kr[1][i]) != find(0, kr[0][i]) ||
        find(1, kr[0][i]) != find(1, kr[1][i])) {
      printf("NO");
      return 0;
    }
  for (int i = 1; i <= k; i++)
    if (find(0, hr[0][i]) != find(0, hr[1][i]) ||
        find(1, hr[0][i]) != find(1, hr[1][i])) {
      printf("NO");
      return 0;
    }
  printf("YES");
}
