#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1100;
const int MAXL = 20;
struct Key {
  int a, b;
} key[MAXN];
struct Person {
  char name[MAXL];
  int inwh;
} p[MAXN];
struct Room {
  bool hasp[MAXN];
  bool haskey[MAXN];
} room[MAXN], room2[MAXN];
int fa[MAXN], fa2[MAXN];
int n, m, k;
int Find(int wh) {
  if (fa[wh] == wh) return wh;
  fa[wh] = Find(fa[wh]);
  return fa[wh];
}
int Find2(int wh) {
  if (fa2[wh] == wh) return wh;
  fa2[wh] = Find2(fa2[wh]);
  return fa2[wh];
}
int Uion(int p1, int p2) {
  for (int i = 1; i <= m; i++) {
    room[p1].haskey[i] |= room[p2].haskey[i];
  }
  for (int i = 1; i <= k; i++) {
    room[p1].hasp[i] |= room[p2].hasp[i];
  }
  return 0;
}
bool Search(int wh) {
  for (int i = 1; i <= m; i++) {
    if (room[wh].haskey[i] == false) continue;
    if (Find(key[i].a) != wh && Find(key[i].b) != wh) continue;
    if (Find(key[i].a) == wh && Find(key[i].b) == wh) continue;
    if (Find(key[i].a) != wh) {
      Uion(wh, Find(key[i].a));
      fa[Find(key[i].a)] = wh;
    } else {
      Uion(wh, Find(key[i].b));
      fa[Find(key[i].b)] = wh;
    }
    return true;
  }
  return false;
}
int Solve() {
  for (int i = 1; i <= n; i++) {
    while (1) {
      if (Search(Find(i)) == false) break;
    }
  }
  return 0;
}
int Init() {
  for (int i = 1; i <= n; i++) {
    fa[i] = i;
    for (int j = 1; j <= m; j++) room[i].haskey[j] = false;
    for (int j = 1; j <= k; j++) room[i].hasp[j] = false;
  }
  return 0;
}
bool Dif() {
  for (int i = 1; i <= n; i++) {
    int a = i;
    int b = Find(i);
    int c = Find2(a);
    int d = Find2(b);
    if (c != d) return false;
    for (int j = 1; j <= m; j++)
      if (room[b].haskey[j] != room2[d].haskey[j]) return false;
    for (int j = 1; j <= k; j++) {
      if (room[b].hasp[j] != room2[d].hasp[j]) return false;
    }
  }
  return true;
}
int main() {
  scanf("%d %d %d", &n, &m, &k);
  Init();
  for (int i = 1; i <= m; i++) {
    scanf("%d %d", &key[i].a, &key[i].b);
  }
  for (int i = 1; i <= k; i++) {
    scanf("%s", p[i].name);
    int a, b;
    scanf("%d", &a);
    room[a].hasp[i] = true;
    p[i].inwh = a;
    scanf("%d", &a);
    for (int j = 1; j <= a; j++) {
      scanf("%d", &b);
      room[p[i].inwh].haskey[b] = true;
    }
  }
  Solve();
  for (int i = 1; i <= n; i++) {
    room2[i] = room[i];
    fa2[i] = fa[i];
  }
  Init();
  for (int i = 1; i <= k; i++) {
    char name[20];
    scanf("%s", name);
    int wh = 1;
    for (wh; wh <= k; wh++)
      if (strcmp(p[wh].name, name) == 0) break;
    int a, b;
    scanf("%d", &a);
    room[a].hasp[wh] = true;
    p[wh].inwh = a;
    wh = a;
    scanf("%d", &a);
    for (; a > 0; a--) {
      scanf("%d", &b);
      room[wh].haskey[b] = true;
    }
  }
  Solve();
  if (Dif() == true)
    puts("YES");
  else
    puts("NO");
  return 0;
}
