#include <bits/stdc++.h>
using namespace std;
const int mn = 2100;
struct node {
  int x, y;
} d[mn];
int rt[mn], h[mn], h2[mn], f[mn];
int n, m, K;
string st;
map<string, int> Q;
bool vis[mn], vis1[mn];
void lose() {
  cout << "NO" << endl;
  exit(0);
}
int fat(int r) {
  if (f[r] != r) f[r] = fat(f[r]);
  return f[r];
}
void merge() {
  memset(vis, 0, sizeof vis);
  int i, x, y, z;
  for (i = 1; i <= n; ++i) f[i] = i;
  for (bool upd = 1; upd;) {
    upd = 0;
    for (i = 1; i <= m; ++i)
      if (!vis[i]) {
        x = fat(d[i].x), y = fat(d[i].y), z = fat(h[rt[i]]);
        if (x == z || y == z) {
          vis[i] = 1;
          upd = 1;
          if (x != y) f[x] = y;
        }
      }
  }
}
int main() {
  cin >> n >> m >> K;
  int i, j, nk;
  for (i = 1; i <= m; ++i) cin >> d[i].x >> d[i].y;
  for (i = 1; i <= K; ++i) {
    cin >> st >> h[i] >> nk;
    Q[st] = i;
    while (nk--) {
      cin >> j;
      rt[j] = i;
    }
  }
  merge();
  memcpy(vis1, vis, sizeof vis);
  int x, y;
  for (i = 1; i <= K; ++i) {
    cin >> st >> h2[i] >> nk;
    int id = Q[st];
    x = fat(h[id]), y = fat(h2[i]);
    if (x != y) lose();
    while (nk--) {
      cin >> j;
      x = fat(h[rt[j]]), y = fat(h2[i]);
      if (x != y) lose();
      rt[j] = i;
    }
  }
  for (i = 1; i <= n; ++i) h[i] = h2[i];
  merge();
  for (i = 1; i <= m; ++i)
    if (vis1[i] != vis[i]) lose();
  cout << "YES" << endl;
  return 0;
}
