#include <bits/stdc++.h>
using namespace std;
map<string, int> Name;
string s;
int a[1005], b[1005], x[1005], y[1005], z[1005], f[1005], n, m, K, p, c, L;
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() {
  cin >> n >> m >> K;
  for (int i = 1; i <= m; i++) cin >> x[i] >> y[i];
  for (int i = 1; i <= K; i++) {
    cin >> s >> p >> L;
    Name[s] = p;
    for (int j = 1; j <= L; j++) cin >> c, z[c] = p;
  }
  work(a);
  for (int i = 1; i <= K; i++) {
    cin >> s >> p >> L;
    int p1 = Name[s];
    if (G(p) - G(p1)) return 0;
    for (int j = 1; j <= L; j++) {
      cin >> c;
      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() {
  puts(solve() ? "YES" : "NO");
  return 0;
}
