#include <bits/stdc++.h>
using namespace std;
int a[1010], b[1010], pos[1010], fa[1010], in[1010], n, m, t, i, j, k, p, room,
    num;
bool v1[1010], v2[1010];
map<string, int> name;
string str;
int get(int x) {
  if (x == fa[x]) return x;
  return fa[x] = get(fa[x]);
}
void solve(bool v[1010]) {
  bool open;
  int i;
  for (i = 1; i <= n; i++) fa[i] = i;
  do {
    open = 0;
    for (i = 1; i <= m; i++)
      if (!v[i] && (get(pos[i]) == get(a[i]) || get(pos[i]) == get(b[i]))) {
        fa[get(b[i])] = get(a[i]);
        v[i] = open = 1;
      }
  } while (open);
}
int main() {
  ios::sync_with_stdio(false);
  cin >> n >> m >> t;
  for (i = 1; i <= m; i++) cin >> a[i] >> b[i];
  for (i = 1; i <= t; i++) {
    cin >> str, name[str] = i;
    cin >> room >> num, in[i] = room;
    for (j = 1; j <= num; j++) cin >> k, pos[k] = room;
  }
  solve(v1);
  for (i = 1; i <= t; i++) {
    cin >> str, p = name[str];
    cin >> room >> num;
    if (get(room) != get(in[p])) {
      puts("NO");
      return 0;
    }
    for (j = 1; j <= num; j++) {
      cin >> k;
      if (get(room) != get(pos[k])) {
        puts("NO");
        return 0;
      }
      pos[k] = room;
    }
  }
  solve(v2);
  for (i = 1; i <= m; i++)
    if (v1[i] ^ v2[i]) {
      puts("NO");
      return 0;
    }
  puts("YES");
  return 0;
}
