#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:836777216")
using namespace std;
int n, m, k;
int dsu[1005];
map<string, int> names;
int keys1[1005];
int keys2[1005];
int people1[1005];
int people2[1005];
bool used[1005];
vector<vector<bool> > p1, p2;
vector<vector<bool> > k1, k2;
pair<int, int> doors[1005];
char s[15];
int parent(int v) { return v == dsu[v] ? v : dsu[v] = parent(dsu[v]); }
void connect(int a, int b) {
  a = parent(a);
  b = parent(b);
  dsu[b] = a;
}
void solve(int people[1005], int keys[1005], vector<vector<bool> > &ppl,
           vector<vector<bool> > &key) {
  memset((used), (0), sizeof((used)));
  for (int(i) = 0; (i) < (n); (i)++) dsu[i] = i;
  queue<int> q;
  for (int(i) = 0; (i) < (m); (i)++) {
    if ((parent(keys[i]) == parent(doors[i].first)) ||
        (parent(keys[i]) == parent(doors[i].second))) {
      q.push(i);
      used[i] = 1;
    }
  }
  while ((int)(q).size()) {
    int top = q.front();
    q.pop();
    if (parent(doors[top].first) != parent(doors[top].second)) {
      connect(doors[top].first, doors[top].second);
    }
    for (int(i) = 0; (i) < (m); (i)++) {
      if (((parent(keys[i]) == parent(doors[i].first)) ||
           (parent(keys[i]) == parent(doors[i].second))) &&
          (parent(doors[i].first) != parent(doors[i].second)) && !used[i]) {
        q.push(i);
        used[i] = 1;
      }
    }
  }
  for (int(i) = 0; (i) < (k); (i)++) {
    for (int(j) = 0; (j) < (n); (j)++) {
      if (parent(people[i]) == parent(j)) {
        ppl[i][j] = 1;
      }
    }
  }
  for (int(i) = 0; (i) < (m); (i)++) {
    for (int(j) = 0; (j) < (n); (j)++) {
      if (parent(keys[i]) == parent(j)) {
        key[i][j] = 1;
      }
    }
  }
}
int main(void) {
  scanf("%d%d%d", &n, &m, &k);
  p1.resize(k);
  p2.resize(k);
  for (int(i) = 0; (i) < (k); (i)++) {
    p1[i].resize(n, 0);
    p2[i].resize(n, 0);
  }
  k1.resize(m);
  k2.resize(m);
  for (int(i) = 0; (i) < (m); (i)++) {
    k1[i].resize(n, 0);
    k2[i].resize(n, 0);
  }
  for (int(i) = 0; (i) < (m); (i)++) {
    int x, y;
    scanf("%d%d", &x, &y);
    x--, y--;
    doors[i] = make_pair(x, y);
  }
  for (int(i) = 0; (i) < (k); (i)++) {
    scanf("%s", &s);
    names[(string)s] = i;
    int r, q;
    scanf("%d", &r);
    r--;
    people1[i] = r;
    scanf("%d", &q);
    for (int(j) = 0; (j) < (q); (j)++) {
      int x;
      scanf("%d", &x);
      x--;
      keys1[x] = r;
    }
  }
  for (int(i) = 0; (i) < (k); (i)++) {
    scanf("%s", &s);
    int r, q;
    scanf("%d", &r);
    r--;
    people2[names[(string)s]] = r;
    scanf("%d", &q);
    for (int(j) = 0; (j) < (q); (j)++) {
      int x;
      scanf("%d", &x);
      x--;
      keys2[x] = r;
    }
  }
  solve(people1, keys1, p1, k1);
  solve(people2, keys2, p2, k2);
  bool ok = 1;
  for (int(i) = 0; (i) < (k); (i)++) {
    for (int(j) = 0; (j) < (n); (j)++) {
      if (p1[i][j] != p2[i][j]) {
        ok = 0;
        break;
      }
    }
    if (!ok) break;
  }
  if (!ok) {
    printf("NO\n");
    return 0;
  }
  for (int(i) = 0; (i) < (m); (i)++) {
    for (int(j) = 0; (j) < (n); (j)++) {
      if (k1[i][j] != k2[i][j]) {
        ok = 0;
        break;
        ;
      }
    }
    if (!ok) break;
  }
  if (ok)
    printf("YES\n");
  else
    printf("NO\n");
  return 0;
}
