#include <bits/stdc++.h>
using namespace std;
const int maxN = 1005;
int fa[maxN], a[maxN], b[maxN], at[maxN], in[maxN];
int n, m, k;
bool c1[maxN], c2[maxN];
map<string, int> is;
int find(int x) {
  if (x == fa[x]) return x;
  return fa[x] = find(fa[x]);
}
void make(bool can[]) {
  for (int i = 1; i <= n; ++i) fa[i] = i;
  while (1) {
    bool flag = 0;
    for (int i = 1; i <= m; ++i)
      if (!can[i]) {
        int fx, fy, k;
        fx = find(a[i]);
        fy = find(b[i]);
        k = find(in[i]);
        if (fx == k || fy == k) {
          can[i] = flag = 1;
          fa[fx] = fy;
        }
      }
    if (!flag) break;
  }
}
void init() {
  string name;
  int p, x;
  scanf("%d%d%d", &n, &m, &k);
  for (int i = 1; i <= m; ++i) scanf("%d%d", a + i, b + i);
  for (int i = 1; i <= k; ++i) {
    cin >> name;
    is[name] = i;
    scanf("%d", &p);
    at[i] = p;
    for (scanf("%d", &p); p--;) {
      scanf("%d", &x);
      in[x] = at[i];
    }
  }
  make(c1);
}
bool work() {
  string name;
  int p, x, g;
  for (int i = 1; i <= k; ++i) {
    cin >> name;
    g = is[name];
    scanf("%d", &p);
    if (find(p) != find(at[i])) return 0;
    at[i] = p;
    for (scanf("%d", &p); p--;) {
      scanf("%d", &x);
      if (find(in[x]) != find(at[i])) return 0;
      in[x] = at[i];
    }
  }
  make(c2);
  for (int i = 1; i <= m; ++i)
    if (c1[i] != c2[i]) return 0;
  return 1;
}
int main() {
  init();
  if (work())
    puts("YES");
  else
    puts("NO");
  return 0;
}
