#include <bits/stdc++.h>
using namespace std;
int cond = 1;
const int max_n = 1011;
int f[2][max_n];
pair<string, int> s[2][max_n];
int pos[2][max_n];
int key[2][max_n];
int r[2][max_n];
pair<int, int> t[max_n];
int find(int id, int a) {
  if (f[id][a] != a) f[id][a] = find(id, f[id][a]);
  return f[id][a];
}
void link(int id, int a, int b) {
  a = find(id, a);
  b = find(id, b);
  if (a == b) return;
  if (r[id][a] > r[id][b]) swap(a, b);
  f[id][a] = b;
  if (r[id][a] == r[id][b]) ++r[id][b];
}
int main() {
  int n, m, k;
  scanf("%d%d%d", &n, &m, &k);
  for (__typeof(1) i = (1); i <= (m); ++i)
    scanf("%d%d", &t[i].first, &t[i].second);
  for (int i = 0; i < (2); i++) {
    char buf[20];
    for (__typeof(1) j = (1); j <= (n); ++j) {
      f[i][j] = j;
      r[i][j] = 0;
    }
    for (int j = 0; j < (k); j++) {
      scanf("%s", buf);
      scanf("%d", &pos[i][j]);
      s[i][j].first = buf;
      s[i][j].second = pos[i][j];
      int a, b;
      scanf("%d", &a);
      while (a--) {
        scanf("%d", &b);
        key[i][b] = pos[i][j];
      }
    }
    for (int u = 0; u < (n); u++) {
      for (__typeof(1) l = (1); l <= (m); ++l)
        if (find(i, t[l].first) != find(i, t[l].second) &&
            (find(i, t[l].first) == find(i, key[i][l]) ||
             find(i, t[l].second) == find(i, key[i][l]))) {
          link(i, t[l].first, t[l].second);
        }
    }
  }
  for (int i = 0; i < (2); i++) sort(s[i], s[i] + k);
  bool ok = true;
  for (int i = 0; i < (k); i++)
    for (__typeof(1) j = (1); j <= (n); ++j) {
      if ((find(0, s[0][i].second) == find(0, j)) !=
          (find(1, s[1][i].second) == find(1, j)))
        ok = false;
    }
  for (__typeof(1) i = (1); i <= (m); ++i)
    if (find(0, key[0][i]) != find(0, key[1][i])) ok = false;
  puts(ok ? "YES" : "NO");
  return 0;
}
