#include <bits/stdc++.h>
using namespace std;
const int maxn = 1005;
int n, m, k, ri[maxn], rl[maxn], t, key, pi[maxn], pl[maxn], cnt, fa[maxn];
bool vi[maxn], vl[maxn];
pair<int, int> e[maxn];
map<string, int> no;
char name[maxn];
int getanc(int x) { return fa[x] <= 0 ? x : fa[x] = getanc(fa[x]); }
void solve(int r[], bool v[], int p[]) {
  for (int i = 1; i <= n; i++) fa[i] = 0;
  for (bool succ = true; succ;) {
    succ = false;
    for (int i = 0; i < m; i++) {
      int a = getanc(e[i].first), b = getanc(e[i].second), c = getanc(r[p[i]]);
      if (!v[i] && (a == c || b == c)) {
        v[i] = succ = true;
        if (a != b) fa[a] = b;
      }
    }
  }
}
void end(const char str[]) {
  printf("%s", str);
  exit(0);
}
int main() {
  scanf("%d%d%d", &n, &m, &k);
  for (int i = 0; i < m; i++) scanf("%d%d", &e[i].first, &e[i].second);
  for (int i = 1; i <= k; i++) {
    scanf("%s%d%d", name, ri + i, &t);
    no[(string)name] = i;
    while (t--) scanf("%d", &key), pi[key - 1] = i;
  }
  solve(ri, vi, pi);
  for (int i = 1; i <= k; i++) {
    scanf("%s", name);
    int id = no[(string)name];
    scanf("%d%d", rl + id, &t);
    if (getanc(ri[id]) != getanc(rl[id])) end("NO");
    while (t--) {
      scanf("%d", &key);
      key--;
      pl[key] = id;
      if (getanc(ri[pi[key]]) != getanc(rl[id])) end("NO");
    }
  }
  solve(rl, vl, pl);
  for (int i = 0; i < m; i++)
    if (vi[i] ^ vl[i]) end("NO");
  end("YES");
  return 0;
}
