#include <bits/stdc++.h>
using namespace std;
int fa[1111], pos[1111];
int mas1[1111], mas2[1111], g1[1111], g2[1111], ex[1111], ey[1111], pos1[1111],
    pos2[1111];
int n, m, K;
map<string, int> G;
int find(int x) { return (fa[x] == x) ? x : (fa[x] = find(fa[x])); }
void solve(int mas[], int g[], int pos[], int model) {
  for (int i = 1; i <= K; ++i) {
    string s;
    int n2, e;
    cin >> s;
    int v = (model) ? G[s] : i;
    scanf("%d%d", &pos[v], &n2);
    for (; n2--;) {
      scanf("%d", &e);
      mas[e] = v;
    }
    G[s] = v;
  }
  for (int i = 1; i <= n; ++i) fa[i] = i;
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= m; ++j) {
      int x = find(ex[j]), y = find(ey[j]), z = find(pos[mas[j]]);
      if (y == z || x == z) fa[max(x, y)] = min(x, y);
    }
  for (int i = 1; i <= n; ++i) g[i] = find(i);
}
int main() {
  scanf("%d%d%d", &n, &m, &K);
  for (int i = 1; i <= m; ++i) scanf("%d%d", &ex[i], &ey[i]);
  solve(mas1, g1, pos1, 0);
  solve(mas2, g2, pos2, 1);
  for (int i = 1; i <= n; ++i)
    if (g1[i] != g2[i]) {
      puts("NO");
      return 0;
    }
  for (int i = 1; i <= K; ++i)
    if (g1[pos1[i]] != g2[pos2[i]]) {
      puts("NO");
      return 0;
    }
  for (int i = 1; i <= m; ++i)
    if (g1[pos1[mas1[i]]] != g2[pos2[mas2[i]]]) {
      puts("NO");
      return 0;
    }
  puts("YES");
}
