#include <bits/stdc++.h>
using namespace std;
string filename = "test";
vector<pair<int, int> > doors;
struct Hab {
  string name;
  int room;
  set<int> keys;
};
vector<Hab> habs[2];
int color_of_hab[2][1001];
int color_of_room[2][1001];
set<int> color_rooms[2][1001];
set<int> color_habs[2][1001];
int main() {
  int n, m, k;
  int x, y;
  string str;
  scanf("%d %d %d", &n, &m, &k);
  for (int _n(m), i(0); i < _n; i++) {
    scanf("%d %d", &x, &y);
    doors.push_back(pair<int, int>(x - 1, y - 1));
  }
  vector<Hab> habst;
  for (int _n(2), iii(0); iii < _n; iii++) {
    for (int _n(k), i(0); i < _n; i++) {
      Hab hab;
      cin >> hab.name;
      cin >> hab.room;
      --hab.room;
      cin >> x;
      for (int _n(x), j(0); j < _n; j++) {
        scanf("%d", &y);
        hab.keys.insert(y - 1);
      }
      if (iii == 0)
        habs[0].push_back(hab);
      else
        habst.push_back(hab);
    }
  }
  for (int _n(habs[0].size()), i(0); i < _n; i++) {
    for (int _n(habst.size()), j(0); j < _n; j++)
      if (habs[0][i].name == habst[j].name) {
        habs[1].push_back(habst[j]);
        break;
      }
  }
  vector<Hab> habs_copy[2];
  for (int _n(2), index(0); index < _n; index++) {
    habs_copy[index] = habs[index];
    for (int _n(k), i(0); i < _n; i++) {
      color_of_hab[index][i] = habs[index][i].room;
      color_habs[index][color_of_hab[index][i]].insert(i);
    }
    for (int _n(n), i(0); i < _n; i++) {
      color_of_room[index][i] = i;
      color_rooms[index][i].insert(i);
    }
    while (true) {
      bool changed = false;
      for (int _n(k), i(0); i < _n; i++) {
        if (!habs[index][i].keys.empty()) {
          for (set<int>::iterator it = habs[index][i].keys.begin();
               it != habs[index][i].keys.end();) {
            int key = *it;
            int ncolor = color_of_room[index][doors[key].first];
            int ocolor = color_of_room[index][doors[key].second];
            if (ncolor != ocolor && (color_of_hab[index][i] == ocolor ||
                                     color_of_hab[index][i] == ncolor)) {
              changed = true;
              habs[index][i].keys.erase(it++);
              for (set<int>::const_iterator ith =
                       color_habs[index][ocolor].begin();
                   ith != color_habs[index][ocolor].end(); ++ith) {
                color_of_hab[index][*ith] = ncolor;
                color_habs[index][ncolor].insert(*ith);
              }
              color_habs[index][ocolor].clear();
              for (set<int>::const_iterator itr =
                       color_rooms[index][ocolor].begin();
                   itr != color_rooms[index][ocolor].end(); ++itr) {
                color_of_room[index][*itr] = ncolor;
                color_rooms[index][ncolor].insert(*itr);
              }
              color_rooms[index][ocolor].clear();
            } else {
              ++it;
            }
          }
        }
      }
      if (!changed) break;
    }
  }
  bool res = true;
  for (int _n(n), i(0); i < _n; i++)
    if (!color_habs[0][i].empty()) {
      bool now = false;
      int old_size = color_habs[0][i].size();
      for (int _n(n), j(0); j < _n; j++) {
        if (color_habs[1][j].size() == old_size) {
          if (color_habs[1][j] == color_habs[0][i]) {
            now = true;
            set<int> old_keys;
            for (set<int>::const_iterator it = color_habs[0][i].begin();
                 it != color_habs[0][i].end(); ++it) {
              old_keys.insert(habs_copy[0][*it].keys.begin(),
                              habs_copy[0][*it].keys.end());
            }
            for (set<int>::const_iterator it = color_habs[1][j].begin();
                 it != color_habs[1][j].end(); ++it) {
              if (color_rooms[0][i].find(habs_copy[1][*it].room) ==
                  color_rooms[0][i].end()) {
                now = false;
                break;
              }
              for (set<int>::const_iterator itk =
                       habs_copy[1][*it].keys.begin();
                   itk != habs_copy[1][*it].keys.end(); ++itk)
                if (old_keys.find(*itk) == old_keys.end()) {
                  now = false;
                  break;
                }
              if (!now) break;
            }
            break;
          }
        }
      }
      if (!now) {
        res = false;
        break;
      }
    }
  if (res)
    cout << "YES\n";
  else
    cout << "NO\n";
  return 0;
}
