#include <bits/stdc++.h>
using namespace std;
int n, m, k;
pair<int, int> E[10000];
int fa[10000];
vector<int> unExpandedEdge[10000], Point[10000];
vector<string> Name[10000];
int getfa(int x) {
  if (x == fa[x]) return x;
  return fa[x] = getfa(fa[x]);
}
vector<pair<pair<vector<int>, vector<int> >, vector<string> > > doit() {
  for (int i = (1); i <= (n); i++) {
    fa[i] = i;
    unExpandedEdge[i].clear();
    Name[i].clear();
    Point[i].clear();
    Point[i].push_back(i);
  }
  queue<int> Q;
  for (int i = (1); i <= (k); i++) {
    string s;
    cin >> s;
    int x, tot;
    scanf("%d%d", &x, &tot);
    while (tot--) {
      int e;
      scanf("%d", &e);
      if (E[e].first == x || E[e].second == x)
        Q.push(e);
      else
        unExpandedEdge[x].push_back(e);
    }
    Name[x].push_back(s);
  }
  while (!Q.empty()) {
    int e = Q.front();
    Q.pop();
    int x = getfa(E[e].first), y = getfa(E[e].second);
    if (x != y) {
      fa[x] = y;
      for (typeof((Name[x]).begin()) s = (Name[x]).begin();
           s != (Name[x]).end(); s++)
        Name[y].push_back(*s);
      for (typeof((Point[x]).begin()) s = (Point[x]).begin();
           s != (Point[x]).end(); s++)
        Point[y].push_back(*s);
      for (typeof((unExpandedEdge[y]).begin()) p = (unExpandedEdge[y]).begin();
           p != (unExpandedEdge[y]).end(); p++)
        unExpandedEdge[x].push_back(*p);
      unExpandedEdge[y].clear();
      for (typeof((unExpandedEdge[x]).begin()) p = (unExpandedEdge[x]).begin();
           p != (unExpandedEdge[x]).end(); p++) {
        int i = getfa(E[*p].first), j = getfa(E[*p].second);
        if (i == y || j == y)
          Q.push(*p);
        else
          unExpandedEdge[y].push_back(*p);
      }
    }
  }
  vector<pair<pair<vector<int>, vector<int> >, vector<string> > > ret;
  for (int i = (1); i <= (n); i++)
    if (getfa(i) == i) {
      sort((Name[i]).begin(), (Name[i]).end());
      sort((Point[i]).begin(), (Point[i]).end());
      sort((unExpandedEdge[i]).begin(), (unExpandedEdge[i]).end());
      ret.push_back(make_pair(make_pair(Point[i], unExpandedEdge[i]), Name[i]));
    }
  sort((ret).begin(), (ret).end());
  return ret;
}
int main() {
  cin >> n >> m >> k;
  for (int i = (1); i <= (m); i++) scanf("%d%d", &E[i].first, &E[i].second);
  if (doit() != doit())
    puts("NO");
  else
    puts("YES");
  return 0;
}
