#include <bits/stdc++.h>
using namespace std;
const int maxn = 3001;
typedef int d1[maxn];
int n, m, K;
d1 u, v, f, team, sit, room, rit, peo;
map<string, int> maple;
int find(int x) { return (f[x] == x) ? x : (f[x] = find(f[x])); }
void work() {
  int i, j;
  int num = 0;
  for (i = 1; i <= n; ++i) f[i] = i;
  for (bool con = true; con;) {
    con = false;
    for (j = 1; j <= m; ++j)
      if (find(u[j]) != find(v[j]))
        if (find(u[j]) == find(sit[j]) || find(v[j]) == find(sit[j]))
          con = true, f[find(u[j])] = find(v[j]);
  }
  for (i = 1; i <= n; ++i) find(i);
  for (i = 1; i <= n; ++i)
    if (team[f[i]] == 0) team[f[i]] = ++num;
}
int main() {
  int i, j, k, l;
  string st;
  bool ok = true;
  scanf("%d%d%d", &n, &m, &K);
  for (i = 1; i <= m; ++i) scanf("%d%d", &u[i], &v[i]);
  for (i = 1; i <= K; ++i) {
    cin >> st;
    maple[st] = i;
    scanf("%d", &room[i]);
    scanf("%d", &j);
    while (j--) scanf("%d", &k), sit[k] = room[i];
  }
  work();
  for (i = 1; i <= m; ++i) rit[i] = team[f[sit[i]]];
  for (i = 1; i <= K; ++i) peo[i] = team[f[room[i]]];
  memset(team, 0, sizeof(team));
  for (l = 1; l <= K; ++l) {
    cin >> st;
    i = maple[st];
    scanf("%d", &room[i]);
    scanf("%d", &j);
    while (j--) scanf("%d", &k), sit[k] = room[i];
  }
  work();
  ok = true;
  for (i = 1; i <= m; ++i)
    if (rit[i] != team[f[sit[i]]]) {
      ok = false;
    }
  for (i = 1; i <= K; ++i)
    if (peo[i] != team[f[room[i]]]) {
      ok = false;
    }
  if (ok)
    printf("YES");
  else
    printf("NO");
  return 0;
}
