#include <bits/stdc++.h>
using namespace std;
int n, m, k;
int from[1000], to[1000];
map<string, int> ma;
int mac = 0;
char s[1005];
int getHash(string s) {
  auto it = ma.find(s);
  if (it == ma.end()) {
    ma[s] = mac;
    return mac++;
  }
  return it->second;
}
struct State {
  vector<int> pp[1000], ke[1000];
  int krn[1000], prn[1000];
  int par[1000], num[1000];
  bool closed[1000];
  int dsuParent(int v) {
    if (v == par[v]) return v;
    return par[v] = dsuParent(par[v]);
  }
  void dsuMerge(int u, int v) {
    u = dsuParent(u);
    v = dsuParent(v);
    if (u == v) return;
    if (pp[u].size() + ke[u].size() < pp[v].size() + ke[v].size()) {
      swap(u, v);
    }
    par[v] = u;
    for (int x : pp[v]) {
      pp[u].push_back(x);
      prn[x] = u;
    }
    pp[v].clear();
    for (int x : ke[v]) {
      ke[u].push_back(x);
      krn[x] = u;
    }
    ke[v].clear();
  }
  void solve() {
    for (int i = 0; i < (int)(m); ++i) krn[i] = -1;
    for (int i = 0; i < (int)(n); ++i) par[i] = i;
    for (int i = 0; i < (int)(k); ++i) {
      int rn, kcnt;
      scanf("%s%d%d", s, &rn, &kcnt), --rn;
      int cur = getHash(string(s));
      pp[rn].push_back(cur);
      prn[cur] = rn;
      for (int j = 0; j < (int)(kcnt); ++j) {
        int x;
        scanf("%d", &x), --x;
        ke[rn].push_back(x);
        krn[x] = rn;
      }
    }
    for (int i = 0; i < (int)(m); ++i) closed[i] = true;
    while (true) {
      bool done = true;
      for (int i = 0; i < (int)(m); ++i)
        if (closed[i] &&
            (krn[i] == dsuParent(from[i]) || krn[i] == dsuParent(to[i]))) {
          closed[i] = false;
          done = false;
          dsuMerge(from[i], to[i]);
        }
      if (done) break;
    }
    for (int i = 0; i < (int)(n); ++i) num[i] = -1;
    for (int i = 0; i < (int)(n); ++i) {
      int ii = dsuParent(i);
      num[ii] = max(num[ii], i);
    }
  }
};
State state1, state2;
int main() {
  scanf("%d%d%d", &n, &m, &k);
  for (int i = 0; i < (int)(m); ++i)
    scanf("%d%d", from + i, to + i), --from[i], --to[i];
  state1.solve();
  state2.solve();
  bool ok = true;
  for (int i = 0; i < (int)(n); ++i)
    if (state1.num[state1.dsuParent(i)] != state2.num[state2.dsuParent(i)]) {
      ok = false;
      break;
    }
  if (ok)
    for (int i = 0; i < (int)(m); ++i)
      if (state1.num[state1.krn[i]] != state2.num[state2.krn[i]]) {
        ok = false;
        break;
      }
  if (ok)
    for (int i = 0; i < (int)(k); ++i)
      if (state1.num[state1.prn[i]] != state2.num[state2.prn[i]]) {
        ok = false;
        break;
      }
  if (ok)
    printf("YES\n");
  else
    printf("NO\n");
  return 0;
}
