#include <bits/stdc++.h>
using namespace std;
int N, M, K;
struct Edge {
  int u, v;
  int used;
} e[1010];
struct Person {
  char name[13];
  int pos;
} per1[1010], per2[1010];
int pkey1[1010], pkey2[1010];
bool Cmp(const Person &i, const Person &j) {
  return strcmp(i.name, j.name) > 0;
}
void Init() {
  scanf("%d%d%d", &N, &M, &K);
  for (int i = 1; i <= M; i++) {
    scanf("%d%d", &e[i].u, &e[i].v);
    e[i].used = 0;
  }
  for (int i = 0; i < K; i++) {
    scanf("%s%d", &per1[i].name, &per1[i].pos);
    int s, t;
    scanf("%d", &s);
    for (int j = 0; j < s; j++) {
      scanf("%d", &t);
      pkey1[t] = per1[i].pos;
    }
  }
  sort(per1, per1 + K, Cmp);
  for (int i = 0; i < K; i++) {
    scanf("%s%d", &per2[i].name, &per2[i].pos);
    int s, t;
    scanf("%d", &s);
    for (int j = 0; j < s; j++) {
      scanf("%d", &t);
      pkey2[t] = per2[i].pos;
    }
  }
  sort(per2, per2 + K, Cmp);
}
int fat1[1010], fat2[1010];
int Find(int x, int *fat) {
  return fat[x] < 0 ? x : fat[x] = Find(fat[x], fat);
}
bool Judge(int x, int y, int *fat) { return Find(x, fat) == Find(y, fat); }
void Union(int x, int y, int *fat) {
  x = Find(x, fat);
  y = Find(y, fat);
  if (x == y) return;
  if (fat[x] > fat[y]) swap(x, y);
  fat[x] += fat[y];
  fat[y] = x;
}
void Solve(int e_, Person *per, int *pkey, int *fat) {
  memset(fat, -1, sizeof(int) * 1010);
  bool flag;
  for (int i = 1; i <= M; i++) {
    flag = 0;
    for (int j = 1; j <= M; j++)
      if (!(e[j].used & e_)) {
        if (Judge(e[j].u, pkey[j], fat) || Judge(e[j].v, pkey[j], fat)) {
          e[j].used |= e_;
          Union(e[j].u, e[j].v, fat);
          flag = 1;
        }
      }
    if (!flag) break;
  }
}
bool Solve() {
  Solve(1, per1, pkey1, fat1);
  Solve(2, per2, pkey2, fat2);
  for (int j = 1; j <= M; j++)
    if ((e[j].used & 1) ^ (e[j].used >> 1)) return 0;
  for (int i = 1; i <= N; i++) {
    for (int j = 1; j < i; j++)
      if (Judge(i, j, fat1) ^ Judge(i, j, fat2)) return 0;
    for (int j = 0; j < K; j++)
      if (Judge(i, per1[j].pos, fat1) ^ Judge(i, per2[j].pos, fat2)) return 0;
    for (int j = 1; j <= M; j++)
      if (Judge(i, pkey1[j], fat1) ^ Judge(i, pkey2[j], fat2)) return 0;
  }
  return 1;
}
int main() {
  Init();
  printf("%s\n", Solve() ? "YES" : "NO");
  return 0;
}
