#include <bits/stdc++.h>
using namespace std;
const int maxn = 1010;
int n, m, k;
pair<int, int> e[maxn];
int lab[maxn];
int used[2][maxn], id[maxn];
map<string, int> cur;
int get(int first) {
  return lab[first] < 0 ? first : lab[first] = get(lab[first]);
}
void unite(int u, int v) {
  if (u == v) return;
  if (lab[u] < lab[v]) {
    lab[v] = u;
  } else {
    if (lab[u] == lab[v]) lab[v]--;
    lab[u] = v;
  }
}
int main() {
  cin >> n >> m >> k;
  for (int i = (1), _b = (m); i <= _b; ++i) cin >> e[i].first >> e[i].second;
  for (int i = (1), _b = (k); i <= _b; ++i) {
    string s;
    cin >> s;
    cin >> cur[s];
    int first, second;
    cin >> first;
    while (first--) cin >> second, id[second] = cur[s];
  }
  for (int i = (1), _b = (n); i <= _b; ++i) lab[i] = -1;
  for (int t = (1), _b = (m); t <= _b; ++t) {
    for (int i = (1), _b = (m); i <= _b; ++i) {
      if (get(id[i]) == get(e[i].first) || get(id[i]) == get(e[i].second)) {
        unite(get(e[i].first), get(e[i].second));
        used[0][i] = true;
      }
    }
  }
  for (int i = (1), _b = (k); i <= _b; ++i) {
    string s;
    cin >> s;
    int first, second;
    cin >> first;
    if (get(first) != get(cur[s])) {
      cout << "NO";
      return 0;
    }
    cur[s] = first;
    cin >> first;
    while (first--) {
      cin >> second;
      if (get(id[second]) != get(cur[s])) {
        cout << "NO";
        return 0;
      }
      id[second] = cur[s];
    }
  }
  for (int i = (1), _b = (n); i <= _b; ++i) lab[i] = -1;
  for (int t = (1), _b = (m); t <= _b; ++t) {
    for (int i = (1), _b = (m); i <= _b; ++i) {
      if (get(id[i]) == get(e[i].first) || get(id[i]) == get(e[i].second)) {
        unite(get(e[i].first), get(e[i].second));
        used[1][i] = true;
      }
    }
  }
  for (int i = (1), _b = (m); i <= _b; ++i)
    if (used[0][i] != used[1][i]) {
      cout << "NO";
      return 0;
    }
  cout << "YES";
  return 0;
}
