#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:836777216")
using namespace std;
int k, n, m;
string s[1111];
bool key[1111][1111];
vector<pair<int, int> > v[1111];
char st[22];
int b[1111];
bool o[1111];
bool u[1111][1111];
vector<int> lt[1111];
bool shit = 1;
void dfs(int guy, int ver) {
  if (u[guy][ver]) return;
  u[guy][ver] = 1;
  for (int i(0); i < (v[ver].size()); i++)
    if (o[v[ver][i].second] || key[guy][v[ver][i].second]) {
      if (!o[v[ver][i].second]) {
        shit = 0;
        o[v[ver][i].second] = 1;
        for (int j(0); j < (lt[v[ver][i].second].size()); j++)
          dfs(lt[v[ver][i].second][j], v[ver][i].first),
              dfs(lt[v[ver][i].second][j], ver);
      }
      dfs(guy, v[ver][i].first);
    } else
      lt[v[ver][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;
    scanf(" %s %d %d", st, b + i, &x);
    b[i]--;
    s[i] = st;
    for (int j(0); j < (x); j++) scanf("%d", &y), y--, key[i][y] = 1;
  }
  for (int i(0); i < (k); i++) dfs(i, b[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--;
    v[x].push_back(pair<int, int>(y, i));
    v[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)
    puts("YES");
  else
    puts("NO");
  return 0;
}
