#include <bits/stdc++.h>
using namespace std;
struct Person {};
const int MAXN = 1005;
const int MAXNAMELEN = 12;
int keys[MAXN][2];
map<string, int> mp;
int keyowner[2][MAXN];
int keypos[2][MAXN];
int ownerpos[2][MAXN];
int fa[2][MAXN];
bool flag[2][MAXN];
int DSU_Father(int a, int *fa) {
  if (fa[a] == a)
    return a;
  else
    return fa[a] = DSU_Father(fa[a], fa);
}
bool DSU_SameSet(int a, int b, int *fa) {
  return DSU_Father(a, fa) == DSU_Father(b, fa);
}
void DSU_Merge(int a, int b, int *fa) {
  if (DSU_SameSet(a, b, fa))
    return;
  else
    fa[DSU_Father(a, fa)] = DSU_Father(b, fa);
  return;
}
int main() {
  int n, m, k;
  char st[MAXNAMELEN];
  bool ans = true;
  scanf("%d%d%d", &n, &m, &k);
  for (int i = 1; i <= m; i++) scanf("%d%d", &keys[i][0], &keys[i][1]);
  for (int i = 1; i <= n; i++) fa[0][i] = fa[1][i] = i;
  for (int j = 0; j < 2; j++)
    for (int i = 0; i < k; i++) {
      int pos, keyn, key, index;
      scanf("%s%d%d", st, &pos, &keyn);
      if (mp.find(st) == mp.end()) mp[st] = i;
      index = mp[st];
      ownerpos[j][index] = pos;
      for (int x = 0; x < keyn; x++)
        scanf("%d", &key), keyowner[j][key] = index, keypos[j][key] = pos;
    }
  for (int j = 0; j < 2; j++)
    for (int t = 0; t < m; t++) {
      bool found = false;
      for (int i = 1; i <= m; i++)
        if (!flag[j][i] && (DSU_SameSet(keys[i][0], keypos[j][i], fa[j]) ||
                            DSU_SameSet(keys[i][1], keypos[j][i], fa[j]))) {
          flag[j][i] = true;
          DSU_Merge(keys[i][0], keys[i][1], fa[j]);
          found = true;
        }
      if (!found) break;
    }
  for (int i = 0; i < k; i++)
    if (!DSU_SameSet(ownerpos[0][i], ownerpos[1][i], fa[0]) ||
        !DSU_SameSet(ownerpos[0][i], ownerpos[1][i], fa[1])) {
      ans = false;
      break;
    }
  if (ans)
    for (int i = 1; i <= m; i++)
      if (!DSU_SameSet(keypos[0][i], keypos[1][i], fa[0]) ||
          !DSU_SameSet(keypos[0][i], keypos[1][i], fa[1])) {
        ans = false;
        break;
      }
  if (ans)
    for (int i = 1; i <= n; i++) {
      for (int j = i + 1; j <= n; j++)
        if (DSU_SameSet(i, j, fa[0]) != DSU_SameSet(i, j, fa[1])) {
          ans = false;
          break;
        }
      if (!ans) break;
    }
  if (ans)
    printf("YES\n");
  else
    printf("NO\n");
  return 0;
}
