#include <bits/stdc++.h>
using namespace std;
const int maxn = 1009;
bitset<maxn> key[2][maxn], val[2][maxn];
int u[maxn], v[maxn], pa[2][maxn];
map<string, int> Map;
string s;
int n, m, K, a, b, c, d, cnt;
inline int getpa(int pa[maxn], int x) {
  return pa[x] == x ? x : pa[x] = getpa(pa, pa[x]);
}
void solve(bitset<maxn> key[maxn], bitset<maxn> val[maxn], int pa[maxn]) {
  for (int i = (1); i <= int(K); i++) {
    cin >> s;
    if (Map.count(s))
      a = Map[s];
    else
      Map[s] = a = ++cnt;
    scanf("%d%d", &b, &c);
    val[b][a] = 1;
    while (c--) {
      scanf("%d", &d);
      key[b][d] = 1;
    }
  }
  for (int i = (1); i <= int(n); i++) pa[i] = i;
  for (int j = (1); j <= int(n - 1); j++)
    for (int i = (1); i <= int(m); i++)
      if (getpa(pa, u[i]) != getpa(pa, v[i]) &&
          (key[getpa(pa, u[i])][i] || key[getpa(pa, v[i])][i])) {
        key[getpa(pa, v[i])] |= key[getpa(pa, u[i])];
        val[getpa(pa, v[i])] |= val[getpa(pa, u[i])];
        pa[getpa(pa, u[i])] = v[i];
      }
}
int main() {
  scanf("%d%d%d", &n, &m, &K);
  for (int i = (1); i <= int(m); i++) scanf("%d%d", &u[i], &v[i]);
  solve(key[0], val[0], pa[0]);
  solve(key[1], val[1], pa[1]);
  for (int i = (1); i <= int(n); i++)
    if ((key[0][getpa(pa[0], i)] != key[1][getpa(pa[1], i)]) ||
        (val[1][getpa(pa[1], i)] != val[0][getpa(pa[0], i)])) {
      puts("NO");
      return 0;
    }
  puts("YES");
  return 0;
}
