#include <bits/stdc++.h>
using namespace std;
int n, m, k;
vector<pair<int, int> > doors;
const int MAX_N = 1010;
int keys[MAX_N][MAX_N / 32 + 1];
void addKey(int room, int key) { keys[room][key / 32] |= 1 << (key % 32); }
bool thereIsKey(int room, int key) {
  return keys[room][key / 32] & (1 << (key % 32));
}
void exchangeKeys(int u, int v) {
  for (int i = 0; i <= m / 32; i++)
    keys[u][i] |= keys[v][i], keys[v][i] |= keys[u][i];
}
vector<string> persons;
map<string, int> start, finish;
map<string, vector<int> > startKeys, finishKeys;
bool check() {
  memset(keys, 0, sizeof(keys));
  for (int i = 0; i < k; i++) {
    vector<int> newKeys = startKeys[persons[i]];
    for (int j = 0; j < newKeys.size(); j++)
      addKey(start[persons[i]], newKeys[j]);
  }
  vector<int> scc(n);
  for (int i = 0; i < n; i++) scc[i] = i;
  vector<bool> opened(m, false);
  for (int cnt = 0; cnt < m; cnt++)
    for (int i = 0; i < m; i++)
      if (!opened[i]) {
        int u = doors[i].first, v = doors[i].second;
        if (thereIsKey(u, i) || thereIsKey(v, i)) {
          opened[i] = true;
          if (scc[u] != scc[v]) {
            int a = scc[u], b = scc[v];
            for (int w = 0; w < n; w++) {
              if (scc[w] == a) exchangeKeys(w, v);
              if (scc[w] == b) {
                exchangeKeys(w, u);
                scc[w] = a;
              }
            }
          }
        }
      }
  for (int i = 0; i < k; i++)
    if (scc[start[persons[i]]] != scc[finish[persons[i]]]) return false;
  for (int i = 0; i < k; i++) {
    vector<int> mustKeys = finishKeys[persons[i]];
    for (int j = 0; j < mustKeys.size(); j++)
      if (!thereIsKey(finish[persons[i]], mustKeys[j])) return false;
  }
  return true;
}
int main() {
  cin >> n >> m >> k;
  doors.resize(m);
  for (int i = 0; i < m; i++) {
    cin >> doors[i].first >> doors[i].second;
    doors[i].first--, doors[i].second--;
  }
  persons.resize(k);
  for (int i = 0; i < k; i++) {
    cin >> persons[i];
    int nKeys;
    cin >> start[persons[i]] >> nKeys, start[persons[i]]--;
    startKeys[persons[i]].resize(nKeys);
    for (int j = 0; j < nKeys; j++)
      cin >> startKeys[persons[i]][j], startKeys[persons[i]][j]--;
  }
  string person;
  for (int i = 0; i < k; i++) {
    cin >> person;
    int nKeys;
    cin >> finish[person] >> nKeys, finish[person]--;
    finishKeys[person].resize(nKeys);
    for (int j = 0; j < nKeys; j++)
      cin >> finishKeys[person][j], finishKeys[person][j]--;
  }
  bool ok = check();
  swap(start, finish);
  swap(startKeys, finishKeys);
  ok &= check();
  cout << (ok ? "YES" : "NO") << '\n';
  return 0;
}
