#include <bits/stdc++.h>
using namespace std;
int n, m, k, fa[1005], u[1005], v[1005];
int b1[1005], f1[1005], w1[1005], r1[1005];
int b2[1005], f2[1005], w2[1005], r2[1005];
bool flag[1005][1005], ans;
string s;
map<string, int> mp;
void makeset(int x) {
  for (int i = 1; i <= x; i++) fa[i] = i;
}
int findset(int x) {
  if (fa[x] != x) fa[x] = findset(fa[x]);
  return fa[x];
}
void unionset(int u, int v) {
  int v1 = findset(u);
  int v2 = findset(v);
  if (v1 == v2) return;
  if (v1 < v2) swap(v1, v2);
  fa[v1] = v2;
  for (int i = 1; i <= m; i++)
    if (flag[v1][i]) flag[v2][i] = 1;
}
int main() {
  scanf("%d%d%d", &n, &m, &k);
  makeset(n);
  for (int i = 1; i <= m; i++) scanf("%d%d", &u[i], &v[i]);
  for (int i = 1; i <= k; i++) {
    cin >> s;
    int x, len, y;
    scanf("%d%d", &x, &len);
    r1[i] = x;
    mp[s] = i;
    for (int i = 1; i <= len; i++) {
      scanf("%d", &y);
      w1[y] = x;
      flag[x][y] = 1;
    }
  }
  for (int j = 1; j <= m; j++)
    for (int i = 1; i <= m; i++) {
      if (!b1[i] && (flag[findset(u[i])][i] || flag[findset(v[i])][i])) {
        unionset(u[i], v[i]);
        b1[i] = 1;
      }
    }
  for (int i = 1; i <= n; i++) f1[i] = findset(i);
  for (int i = 1; i <= m; i++) w1[i] = findset(w1[i]);
  for (int i = 1; i <= k; i++) r1[i] = findset(r1[i]);
  makeset(n);
  memset(flag, 0, sizeof(flag));
  for (int i = 1; i <= k; i++) {
    cin >> s;
    int x, len, y;
    scanf("%d%d", &x, &len);
    r2[mp[s]] = x;
    for (int i = 1; i <= len; i++) {
      scanf("%d", &y);
      w2[y] = x;
      flag[x][y] = 1;
    }
  }
  for (int j = 1; j <= m; j++)
    for (int i = 1; i <= m; i++) {
      if (!b2[i] && (flag[findset(u[i])][i] || flag[findset(v[i])][i])) {
        unionset(u[i], v[i]);
        b2[i] = 1;
      }
    }
  for (int i = 1; i <= n; i++) f2[i] = findset(i);
  for (int i = 1; i <= m; i++) w2[i] = findset(w2[i]);
  for (int i = 1; i <= k; i++) r2[i] = findset(r2[i]);
  for (int i = 1; i <= n; i++)
    if (f1[i] != f2[i]) ans = 1;
  for (int i = 1; i <= n; i++)
    if (w1[i] != w2[i]) ans = 1;
  for (int i = 1; i <= n; i++)
    if (r1[i] != r2[i]) ans = 1;
  for (int i = 1; i <= m; i++)
    if (b1[i] != b2[i]) ans = 1;
  if (ans)
    printf("NO\n");
  else
    printf("YES\n");
}
