#include <bits/stdc++.h>
using namespace std;
const int N = 1010;
int n, m, k;
int a[N], b[N], f1[N], f2[N], g1[N], g2[N];
int u1[N], u2[N];
int len = 0, S[10100][60], T[10100], LL = 0;
char s[20];
int _name() {
  scanf("%s", s + 1);
  int L = strlen(s + 1), now = 0;
  for (int i = 1, x; i <= L; ++i) {
    if (s[i] >= 'a')
      x = s[i] - 'a' + 26;
    else
      x = s[i] - 'A';
    if (S[now][x] == 0) S[now][x] = (++len);
    now = S[now][x];
  }
  if (T[now] == 0) T[now] = (++LL);
  return T[now];
}
int bcj(int *f, const int x) {
  if (f[x] != x) f[x] = bcj(f, f[x]);
  return f[x];
}
void work(int *f, int *g, int *u) {
  for (int i = 1; i <= n; ++i) f[i] = i;
  for (int i = 1; i <= k; ++i) {
    int x = _name(), y, z;
    scanf("%d%d", &y, &z);
    g[x] = y;
    for (int j = 1; j <= z; ++j) scanf("%d", &x), u[x] = y;
  }
  for (int j = 1; j <= m; ++j)
    for (int i = 1; i <= m; ++i) {
      int o = bcj(f, a[i]), p = bcj(f, b[i]), q = bcj(f, u[i]);
      if (o == q || p == q) f[max(o, p)] = min(o, p);
    }
  for (int i = 1; i <= n; ++i) f[i] = bcj(f, f[i]);
  for (int i = 1; i <= k; ++i) g[i] = bcj(f, g[i]);
  for (int i = 1; i <= m; ++i) u[i] = bcj(f, u[i]);
}
bool YES() {
  for (int i = 1; i <= n; ++i)
    if (f1[i] != f2[i]) return 0;
  for (int i = 1; i <= m; ++i)
    if (u1[i] != u2[i]) return 0;
  for (int i = 1; i <= k; ++i)
    if (g1[i] != g2[i]) return 0;
  return 1;
}
int main() {
  scanf("%d%d%d", &n, &m, &k);
  for (int i = 1; i <= m; ++i) scanf("%d%d", &a[i], &b[i]);
  work(f1, g1, u1);
  work(f2, g2, u2);
  if (YES())
    puts("YES");
  else
    puts("NO");
  return 0;
}
