#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int MAXN = 1001;
int par[MAXN], size[MAXN];
struct FindUnion {
  void init(int n) {
    for (int i = 0; i < n; ++i) par[i] = i, size[i] = 1;
  }
  int root(int x) {
    if (par[x] == x)
      return x;
    else
      return root(par[x]);
  }
  void unite(int x, int y) {
    x = root(x);
    y = root(y);
    if (x == y) return;
    if (size[x] > size[y])
      size[x] += size[y], par[y] = par[x];
    else
      size[y] += size[x], par[x] = par[y];
  }
};
pair<int, int> edge[MAXN];
map<string, int> M;
int n, m, k;
int key[2][MAXN], p[2][MAXN], connected[2][MAXN][MAXN];
void process(int x) {
  FindUnion uf;
  uf.init(n);
  for (int i = 0; i < n + 2; ++i) {
    for (int j = 0; j < m; ++j) {
      int r = uf.root(key[x][j]);
      if (uf.root(edge[j].first) == r || uf.root(edge[j].second) == r)
        uf.unite(edge[j].first, edge[j].second);
    }
  }
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < n; ++j)
      if (uf.root(i) == uf.root(j)) connected[x][i][j] = 1;
}
int main() {
  memset(connected, 0, sizeof(connected));
  scanf("%d %d %d", &n, &m, &k);
  for (int i = 0; i < m; ++i) {
    int x, y;
    scanf("%d %d", &x, &y);
    x--;
    y--;
    edge[i] = make_pair(x, y);
  }
  char s[15];
  for (int i = 0; i < k; ++i) {
    int x, y, z;
    scanf("%s %d %d", s, &x, &y);
    string r = s;
    x--;
    p[0][i] = x;
    M[s] = i;
    for (int j = 0; j < y; ++j) {
      scanf("%d", &z);
      key[0][--z] = x;
    }
  }
  for (int i = 0; i < k; ++i) {
    int x, y, z;
    scanf("%s %d %d", s, &x, &y);
    string r = s;
    x--;
    p[1][M[s]] = x;
    for (int j = 0; j < y; ++j) {
      scanf("%d", &z);
      key[1][--z] = x;
    }
  }
  process(0);
  process(1);
  bool ans = true;
  for (int i = 0; i < k; ++i)
    if (!connected[0][p[0][i]][p[1][i]]) ans = false;
  for (int i = 0; i < k; ++i)
    if (!connected[1][p[0][i]][p[1][i]]) ans = false;
  for (int i = 0; i < m; ++i)
    if (!connected[0][key[0][i]][key[1][i]]) ans = false;
  for (int i = 0; i < m; ++i)
    if (!connected[1][key[0][i]][key[1][i]]) ans = false;
  if (ans == true)
    printf("YES\n");
  else
    printf("NO\n");
  return 0;
}
