#include <bits/stdc++.h>
using namespace std;
int i, j, k, l, n, m, s, an, sum, t;
const int N = 2100;
int fa[N], g[N][N], X[N], Y[N];
class arr {
 public:
  char num[20];
  int w, s, x[N];
} a[N], b[N];
bool ff[N][N];
int td[N], belong1[N], belong2[N];
int t1[N], t2[N], pfa[N], p1[N], p2[N];
int get(int x) {
  if (fa[x] == x) return x;
  fa[x] = get(fa[x]);
  return fa[x];
}
int get2(int x) {
  if (pfa[x] == x) return x;
  pfa[x] = get2(pfa[x]);
  return pfa[x];
}
void dfs(int now) {
  int FA = get(now);
  for (int j = 1; j <= g[now][0]; j++) {
    int p = g[now][j];
    for (int i = 1; i <= a[p].s; i++) ff[FA][a[p].x[i]] = true;
  }
  bool ok = true;
  while (ok) {
    ok = false;
    for (int i = 1; i <= m; i++)
      if (ff[FA][i]) {
        int xx = get(X[i]);
        int yy = get(Y[i]);
        if ((fa[xx] == FA) && (fa[yy] != FA)) {
          fa[yy] = FA;
          dfs(yy);
          ok = true;
          break;
        }
        swap(xx, yy);
        if ((fa[xx] == FA) && (fa[yy] != FA)) {
          fa[yy] = FA;
          dfs(yy);
          ok = true;
          break;
        }
      }
  }
}
void work() {
  memset(ff, false, sizeof(ff));
  memset(g, 0, sizeof(g));
  for (int i = 1; i <= t; i++) {
    getchar();
    scanf("%s", a[i].num + 1);
    scanf("%d%d", &a[i].w, &a[i].s);
    g[a[i].w][++g[a[i].w][0]] = i;
    for (int j = 1; j <= a[i].s; j++)
      scanf("%d", &a[i].x[j]), p1[a[i].x[j]] = a[i].w;
  }
  for (int i = 1; i <= n; i++) fa[i] = i;
  sum = 0;
  for (int i = 1; i <= n; i++)
    if (fa[i] == i) {
      dfs(i);
    }
}
bool cheak(char a[], char b[]) {
  if (strlen(a + 1) != strlen(b + 1)) return false;
  int l = strlen(a + 1);
  for (int i = 1; i <= l; i++) {
    if (a[i] != b[i]) return false;
  }
  return true;
}
int main() {
  scanf("%d%d%d", &n, &m, &t);
  for (int i = 1; i <= m; i++) {
    scanf("%d%d", &X[i], &Y[i]);
  }
  work();
  memcpy(b, a, sizeof(b));
  memcpy(pfa, fa, sizeof(pfa));
  memcpy(p2, p1, sizeof(p2));
  work();
  for (int j = 1; j <= t; j++)
    for (int i = 1; i <= t; i++)
      if (cheak(a[j].num, b[i].num)) {
        if (get2(a[j].w) != get2(b[i].w)) {
          printf("NO");
          exit(0);
        }
        if (get(a[j].w) != get(b[i].w)) {
          printf("NO");
          exit(0);
        }
        break;
      }
  for (int i = 1; i <= m; i++) {
    int x = p1[i];
    if (get2(p1[i]) != get2(p2[i])) {
      printf("NO");
      exit(0);
    }
    if (get(p1[i]) != get(p2[i])) {
      printf("NO");
      exit(0);
    }
  }
  printf("YES");
  return 0;
}
