#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int x = 0;
  char ch = getchar();
  bool positive = 1;
  for (; ch < '0' || ch > '9'; ch = getchar())
    if (ch == '-') positive = 0;
  for (; ch >= '0' && ch <= '9'; ch = getchar()) x = x * 10 + ch - '0';
  return positive ? x : -x;
}
map<string, int> Name;
int a[1005], b[1005], x[1005], y[1005], z[1005], f[1005], n, m, K;
int G(int x) { return f[x] == x ? x : f[x] = G(f[x]); }
void work(int a[]) {
  for (int i = 1; i <= n; i++) f[i] = i;
  int flag = 1;
  while (flag) {
    flag = 0;
    for (int i = 1; i <= m; i++)
      if (!a[i] && (G(x[i]) == G(z[i]) || G(y[i]) == G(z[i])))
        f[G(x[i])] = G(y[i]), a[i] = flag = 1;
  }
}
bool solve() {
  work(a);
  for (int i = 1; i <= K; i++) {
    string s;
    cin >> s;
    int p = read(), L = read();
    int p1 = Name[s];
    if (G(p) != G(p1)) return 0;
    for (int j = 1; j <= L; j++) {
      int c = read();
      if (G(p) != G(z[c])) return 0;
      z[c] = p;
    }
  }
  work(b);
  for (int i = 1; i <= m; i++)
    if (a[i] != b[i]) return 0;
  return 1;
}
int main() {
  n = read(), m = read(), K = read();
  for (int i = 1; i <= m; i++) x[i] = read(), y[i] = read();
  for (int i = 1; i <= K; i++) {
    string s;
    cin >> s;
    int p = read(), L = read();
    Name[s] = p;
    for (int j = 1; j <= L; j++) z[read()] = p;
    ;
  }
  printf(solve() ? "YES\n" : "NO\n");
  return 0;
}
