#include <bits/stdc++.h>
using namespace std;
int k, n, m;
string s[1111];
bool key[1111][1111];
bool u[1111][1111];
vector<pair<int, int>> gr_room[1111];
char st[22];
int Nrooms[1111];
bool o[1111];
vector<int> lt[1111];
void dfs(int guy, int room) {
  if (u[guy][room]) return;
  u[guy][room] = 1;
  for (int i = 0; i < gr_room[room].size(); i++)
    if (o[gr_room[room][i].second] || key[guy][gr_room[room][i].second]) {
      if (!o[gr_room[room][i].second]) {
        o[gr_room[room][i].second] = 1;
        for (int j = 0; j < lt[gr_room[room][i].second].size(); j++) {
          dfs(lt[gr_room[room][i].second][j], gr_room[room][i].first);
          dfs(lt[gr_room[room][i].second][j], room);
        }
      }
      dfs(guy, gr_room[room][i].first);
    } else
      lt[gr_room[room][i].second].push_back(guy);
}
vector<pair<vector<string>, pair<vector<int>, vector<int>>>> solve() {
  for (int i = 0; i < m; i++) lt[i].clear();
  memset(u, false, sizeof(u));
  memset(o, 0, sizeof(o));
  memset(key, false, sizeof(key));
  for (int i = 0; i < k; i++) {
    int x, y;
    cin >> st >> Nrooms[i] >> x;
    Nrooms[i]--;
    s[i] = st;
    for (int j = 0; j < x; j++) {
      cin >> y;
      y--;
      key[i][y] = 1;
    }
  }
  for (int i = 0; i < k; i++) dfs(i, Nrooms[i]);
  vector<pair<vector<string>, pair<vector<int>, vector<int>>>> res(n);
  for (int i = 0; i < k; i++) {
    for (int j = 0; j < n; j++)
      if (u[i][j]) {
        res[j].first.push_back(s[i]);
        if (res[j].second.first.size() == 0)
          for (int q = 0; q < n; q++)
            if (u[i][q]) res[j].second.first.push_back(q);
        for (int q = 0; q < m; q++)
          if (key[i][q]) res[j].second.second.push_back(q);
        break;
      }
  }
  for (int i = 0; i < n; i++) {
    sort(res[i].first.begin(), res[i].first.end());
    sort(res[i].second.second.begin(), res[i].second.second.end());
  }
  sort(res.begin(), res.end());
  return res;
}
int main() {
  cin >> n >> m >> k;
  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    x--, y--;
    gr_room[x].push_back(pair<int, int>(y, i));
    gr_room[y].push_back(pair<int, int>(x, i));
  }
  vector<pair<vector<string>, pair<vector<int>, vector<int>>>> v1 = solve();
  vector<pair<vector<string>, pair<vector<int>, vector<int>>>> v2 = solve();
  if (v1 == v2)
    cout << "YES";
  else
    cout << "NO";
  return 0;
}
