#include <bits/stdc++.h>
using namespace std;
template <class T>
T abs(T x) {
  return x > 0 ? x : -x;
}
int n, r = 0;
int m, k;
int io[2][1000], w[2][1000][1000], g[2][1000][1000], e[2][1000],
    u[2][1000][1000];
deque<pair<int, pair<int, int> > > all;
vector<pair<int, int> > v[1000];
map<string, int> st;
int get(string s) {
  if (st.count(s)) return st[s];
  st[s] = r++;
  return r - 1;
}
int main() {
  cin >> n >> m >> k;
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    v[a].push_back(make_pair(b, i));
    v[b].push_back(make_pair(a, i));
    io[0][i] = io[1][i] = 0;
  }
  for (int t = 0; t < 2; t++) {
    all.clear();
    for (int i = 0; i < k; i++) {
      string s;
      cin >> s;
      int k = get(s), x, y, z;
      cin >> x >> y;
      x--;
      g[t][k][x] = 1;
      for (int j = 0; j < y; j++) {
        cin >> z;
        z--;
        e[t][z] = k;
        w[t][k][z] = 1;
      }
      all.push_back(make_pair(0, make_pair(k, x)));
    }
    while (!all.empty()) {
      int T = all.front().first;
      int x = all.front().second.first;
      int y = all.front().second.second;
      all.pop_front();
      if (T == 0) {
        for (int i = 0; i < ((int)(v[y]).size()); i++) {
          int j = v[y][i].first;
          int k = v[y][i].second;
          if (w[t][x][k] && !io[t][k]) {
            io[t][k] = 1;
            all.push_back(make_pair(1, make_pair(y, j)));
          } else if (io[t][k] && !g[t][x][j]) {
            g[t][x][j] = 1;
            all.push_back(make_pair(0, make_pair(x, j)));
          }
        }
      } else {
        for (int i = 0; i < k; i++) {
          if (g[t][i][x] && !g[t][i][y]) {
            g[t][i][y] = 1;
            all.push_back(make_pair(0, make_pair(i, y)));
          }
          if (g[t][i][y] && !g[t][i][x]) {
            g[t][i][x] = 1;
            all.push_back(make_pair(0, make_pair(i, x)));
          }
        }
      }
    }
    for (int i = 0; i < m; i++)
      for (int j = 0; j < n; j++)
        if (g[t][e[t][i]][j]) u[t][i][j] = 1;
  }
  int ok = 1;
  for (int i = 0; i < m; i++)
    for (int j = 0; j < n; j++) ok &= int(u[0][i][j] == u[1][i][j]);
  for (int i = 0; i < k; i++)
    for (int j = 0; j < n; j++) ok &= int(g[0][i][j] == g[1][i][j]);
  if (ok)
    printf("YES\n");
  else
    printf("NO\n");
  return 0;
}
