#include <bits/stdc++.h>
using namespace std;
int m, n, j, k, l, i, o, p, __t, peo;
int P1[100000], P2[100000];
vector<int> key1[1020], people[1020];
int pp[1020], where[1020];
string s;
map<string, int> N;
char ch;
void read(int &a) {
  for (ch = getchar(); (ch < '0' || ch > '9') && (ch != '-'); ch = getchar())
    ;
  if (ch == '-')
    a = 0, __t = -1;
  else
    a = ch - '0', __t = 1;
  for (ch = getchar(); ch >= '0' && ch <= '9'; ch = getchar())
    a = a * 10 + ch - '0';
  a *= __t;
}
struct edge {
  int a, b;
} Ed[100000];
struct merger_set {
  int F[100000];
  merger_set() {
    for (int i = 0; i < 100000; i++) F[i] = i;
  }
  int G(int P) { return (F[P] == P) ? (P) : (F[P] = G(F[P])); }
  void merger(int a, int b) {
    if (G(a) == G(b)) return;
    F[G(a)] = G(b);
  }
} ms, ms2;
bool solve[100000], place[100000], solve2[100000];
int L[100000], op, ed, pp2[100000];
int main() {
  read(m), read(n), read(peo);
  for (int i = 1; i <= n; i++) {
    read(Ed[i].a), read(Ed[i].b);
  }
  for (int i = 1; i <= peo; i++) {
    cin >> s;
    read(P1[i]);
    N[s] = i;
    read(k);
    for (; k--;) {
      read(l);
      pp[l] = P1[i];
    }
  }
  bool could = 1;
  for (int success = 1; success;) {
    success = 0;
    for (int i = 1; i <= n; i++)
      if (!solve[i]) {
        int p = pp[i];
        if (ms.G(p) == ms.G(Ed[i].a) || ms.G(p) == ms.G(Ed[i].b)) {
          success = 1;
          solve[i] = 1;
          ms.merger(Ed[i].a, Ed[i].b);
        }
      }
  }
  for (int i = 1; i <= peo; i++) {
    read(j);
    if (ms.G(j) != ms.G(P1[i])) {
      could = 0;
      break;
    }
    read(k);
    for (; k--;) {
      read(l);
      pp2[l] = j;
      if (ms.G(j) != ms.G(pp[l])) {
        could = 0;
        break;
      }
    }
  }
  for (int success = 1; success;) {
    success = 0;
    for (int i = 1; i <= n; i++)
      if (!solve2[i]) {
        int p = pp2[i];
        if (ms2.G(p) == ms2.G(Ed[i].a) || ms2.G(p) == ms2.G(Ed[i].b)) {
          success = 1;
          solve2[i] = 1;
          ms2.merger(Ed[i].a, Ed[i].b);
        }
      }
  }
  for (int i = 1; i <= n; i++)
    if (solve[i] ^ solve2[i]) {
      could = 0;
      if (peo == -1) printf("err2\n");
    }
  if (could)
    printf("YES\n");
  else
    printf("NO\n");
}
