#include <bits/stdc++.h>
using namespace std;
const int N = 1010;
int n, m, k, door[N][2], owner[N][2], father[N * 2][2], key[N][N];
int getfather(int x, int d) {
  if (father[x][d] == x) return (x);
  father[x][d] = getfather(father[x][d], d);
  return (father[x][d]);
}
void search(int d) {
  int i;
  bool p = true;
  while (p) {
    p = false;
    for (i = 1; i <= m; i++)
      if (getfather(door[i][0], d) != getfather(door[i][1], d))
        if (getfather(door[i][0], d) == getfather(owner[i][d], d) ||
            getfather(door[i][1], d) == getfather(owner[i][d], d)) {
          p = true;
          if (getfather(door[i][0], d) < getfather(door[i][1], d))
            father[getfather(door[i][1], d)][d] = getfather(door[i][0], d);
          else
            father[getfather(door[i][0], d)][d] = getfather(door[i][1], d);
          father[getfather(owner[i][d], d)][d] = getfather(door[i][0], d);
        }
  }
}
int main() {
  int i, j, l, s, x;
  string name[N], temp;
  cin >> n >> m >> k;
  for (i = 1; i <= m; i++)
    for (j = 0; j <= 1; j++) cin >> door[i][j];
  for (i = 1; i <= k; i++) {
    cin >> name[i] >> x >> s;
    father[i + n][0] = x;
    for (j = 1; j <= s; j++) {
      cin >> x;
      owner[x][0] = i + n;
    }
  }
  for (i = 1; i <= k; i++) {
    cin >> temp >> x >> s;
    for (l = 1; l <= k; l++)
      if (name[l] == temp) break;
    father[l + n][1] = x;
    key[l][0] = s;
    for (j = 1; j <= s; j++) {
      cin >> x;
      owner[x][1] = l + n;
      key[l][j] = x;
    }
  }
  for (i = 1; i <= n; i++)
    for (j = 0; j <= 1; j++) father[i][j] = i;
  search(0);
  search(1);
  for (i = 1; i <= n + k; i++)
    if (getfather(i, 0) != getfather(i, 1)) {
      cout << "NO";
      return (0);
    }
  for (i = 1; i <= k; i++)
    for (j = 1; j <= key[i][0]; j++)
      if (getfather(owner[key[i][j]][0], 1) != getfather(i + n, 1)) {
        cout << "NO";
        return (0);
      }
  cout << "YES";
  return (0);
}
