#include <bits/stdc++.h>
using namespace std;
constexpr int N = 1111;
int n, m, k;
pair<int, int> e[N];
vector<vector<int>> a;
map<string, int> nid;
vector<int> f, pos, ed;
int fnd(int x) { return f[x] ? f[x] = fnd(f[x]) : x; }
void mrg(vector<vector<int>>& a, int x, int y) {
  if (a[x].size() > a[y].size()) swap(x, y);
  f[x] = y;
  for (int z : a[x]) {
    auto [p, q] = e[z];
    if (fnd(p) != fnd(q)) a[y].push_back(z);
  }
  a[x].clear();
}
bool solve(vector<vector<int>> a, vector<int> _pos, const vector<int>& _ed) {
  fill(f.begin(), f.end(), 0);
loop:
  for (int i = 1; i <= n; ++i)
    if (!f[i]) {
      for (int j : a[i]) {
        if (fnd(_pos[j]) != i) continue;
        auto [x, y] = e[j];
        x = fnd(x);
        y = fnd(y);
        if (x == y) continue;
        mrg(a, x, y);
        goto loop;
      }
    }
  for (int i = 1; i <= k + m; ++i) {
    if (fnd(_pos[i]) != fnd(_ed[i])) {
      return false;
    }
  }
  return true;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n >> m >> k;
  a.resize(n + 1, {});
  f.resize(n + 1, 0);
  pos.resize(m + k + 1, 0);
  ed.resize(m + k + 1, 0);
  for (int x, y, i = 1; i <= m; ++i) {
    cin >> x >> y;
    e[i] = {x, y};
    a[x].push_back(i);
    a[y].push_back(i);
  }
  for (int w, nk, i = 1; i <= k; ++i) {
    string s;
    cin >> s >> w >> nk;
    nid[s] = m + i;
    pos[m + i] = w;
    for (int x, j = 0; j < nk; ++j) {
      cin >> x;
      pos[x] = w;
    }
  }
  for (int w, nk, i = 1; i <= k; ++i) {
    string s;
    cin >> s >> w >> nk;
    int who = nid[s];
    ed[who] = w;
    for (int x, j = 0; j < nk; ++j) {
      cin >> x;
      ed[x] = w;
    }
  }
  bool s1 = solve(a, pos, ed);
  bool s2 = solve(a, ed, pos);
  cout << (s1 && s2 ? "YES" : "NO") << endl;
  return 0;
}
