#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007, dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};
const double eps = 1e-8;
void read(int &k) {
  k = 0;
  char x = getchar();
  while (x < '0' || x > '9') x = getchar();
  while (x >= '0' && x <= '9') {
    k = k * 10 - 48 + x;
    x = getchar();
  }
}
int n, m, K, x[1010], y[1010], st, num, t, key[1010], ft[1010], op[1010],
    fir[1010], sec[1010], key0[1010];
char s[1010];
map<string, int> u, v;
int fa(int k) {
  if (ft[k] == k) return k;
  return ft[k] = fa(ft[k]);
}
void solve() {
  int i = 0;
  while (1) {
    for (i = 1; i <= m; i++)
      if (!op[i])
        if (fa(x[i]) == fa(key[i]) || fa(y[i]) == fa(key[i])) {
          ft[fa(x[i])] = fa(y[i]);
          op[i] = 1;
          break;
        }
    if (i > m) break;
  }
}
int main() {
  scanf("%d%d%d", &n, &m, &K);
  for (int i = 1; i <= m; i++) scanf("%d%d", &x[i], &y[i]);
  for (int i = 1; i <= K; i++) {
    scanf("%s%d%d", s, &st, &num);
    u[s] = st;
    for (int j = 1; j <= num; j++) {
      scanf("%d", &t);
      key[t] = st;
    }
  }
  memcpy(key0, key, sizeof key);
  for (int i = 1; i <= n; i++) ft[i] = i;
  solve();
  memcpy(fir, op, sizeof op);
  memset(op, 0, sizeof op);
  for (int i = 1; i <= K; i++) {
    scanf("%s%d%d", s, &st, &num);
    v[s] = st;
    for (int j = 1; j <= num; j++) {
      scanf("%d", &t);
      key[t] = st;
    }
  }
  for (int i = 1; i <= n; i++) ft[i] = i;
  solve();
  memcpy(sec, op, sizeof op);
  for (int i = 1; i <= m; i++)
    if (fir[i] ^ sec[i]) {
      puts("NO");
      return 0;
    }
  for (map<string, int>::iterator it = u.begin(); it != u.end(); it++)
    if (fa(v[it->first]) != fa(it->second)) {
      puts("NO");
      return 0;
    }
  for (int i = 1; i <= m; i++)
    if (fa(key0[i]) != fa(key[i])) {
      puts("NO");
      return 0;
    }
  puts("YES");
  return 0;
}
