#include <bits/stdc++.h>
using namespace std;
const int N = 1005;
map<string, int> mmp;
int x[N], y[N], key[N];
int n, m, k;
bool open1[N], open2[N], ans;
char s[N];
int room, tot, door;
int fa[N];
inline int find(int x) { return x == fa[x] ? x : fa[x] = find(fa[x]); }
void fuck(bool *p) {
  for (int i = 1; i <= n; ++i) fa[i] = i;
  bool pd = true;
  while (pd) {
    pd = false;
    for (int i = 1; i <= m; ++i)
      if (!p[i]) {
        int fk = find(key[i]), fx = find(x[i]), fy = find(y[i]);
        if (fk == fx || fk == fy) {
          fa[fx] = fy;
          pd = p[i] = true;
        }
      }
  }
}
int main() {
  ans = true;
  scanf("%d%d%d", &n, &m, &k);
  for (int i = 1; i <= m; ++i)
    scanf("%d%d", &x[i], &y[i]), open1[i] = open2[i] = false;
  for (int i = 1; i <= k; ++i) {
    scanf("%s%d%d", s, &room, &tot);
    mmp[s] = room;
    while (tot--) {
      scanf("%d", &door);
      key[door] = room;
    }
  }
  fuck(open1);
  for (int i = 1; i <= k; ++i) {
    scanf("%s%d%d", s, &room, &tot);
    ans &= (find(mmp[s]) == find(room));
    while (tot--) {
      scanf("%d", &door);
      ans &= (find(key[door]) == find(room));
      key[door] = room;
    }
  }
  fuck(open2);
  for (int i = 1; i <= m; ++i) ans &= (open1[i] == open2[i]);
  printf(ans ? "YES" : "NO");
}
