#include <bits/stdc++.h>
using namespace std;
bool G[2][1002][1002];
pair<int, int> key[1002];
int components[2][1002];
bool used[2][1010], usedroom[2][1010];
int startkey[2][1002];
struct DSU {
  int sets[1042];
  int sizes[1042];
  void make_set(int v) {
    sets[v] = v;
    sizes[v] = 1;
  }
  int find_set(int v) {
    if (v == sets[v]) return v;
    return sets[v] = find_set(sets[v]);
  }
  void union_sets(int a, int b) {
    a = find_set(a);
    b = find_set(b);
    if (a != b) {
      if (sizes[a] < sizes[b]) swap(a, b);
      sets[b] = a;
      sizes[a] += sizes[b];
    }
  };
  bool check_sets(int a, int b) { return find_set(a) == find_set(b); }
} dsu[2];
void link(int w, int m) {
  bool ok = true;
  while (ok) {
    ok = false;
    for (int i = 1; i <= m; i++) {
      int f = key[i].first, l = key[i].second, r = startkey[w][i];
      if (G[w][f][l] || dsu[w].check_sets(r, l) || dsu[w].check_sets(r, f)) {
        G[w][f][l] = G[w][l][f] = true;
        if (!usedroom[w][l] || !usedroom[w][f] || !used[w][i]) ok = true;
        usedroom[w][l] = usedroom[w][f] = used[w][i] = true;
        dsu[w].union_sets(f, l);
      }
    }
  }
}
void bfs(int w, int n) {
  vector<bool> used(n + 1, false);
  int current = 0;
  for (int i = 1; i <= n;) {
    while (i <= n && used[i]) i++;
    current++;
    queue<int> Q;
    Q.push(i);
    used[i] = true;
    while (!Q.empty()) {
      int cur = Q.front();
      Q.pop();
      components[w][cur] = current;
      for (int i = 1; i <= n; i++)
        if (!used[i] && G[w][i][cur]) {
          used[i] = true;
          Q.push(i);
        }
    }
  }
}
int main() {
  int n, m, k;
  ios_base::sync_with_stdio(false);
  cin >> n >> m >> k;
  map<string, int> start;
  for (int i = 1; i <= m; i++) {
    cin >> key[i].first >> key[i].second;
  }
  for (int i = 1; i <= n; i++) {
    dsu[0].make_set(i);
    dsu[1].make_set(i);
  }
  map<string, int> name_id;
  for (int i = 0; i < k; i++) {
    string s;
    cin >> s;
    int room;
    cin >> room;
    start[s] = room;
    name_id[s] = i + 1;
    int num;
    cin >> num;
    for (int j = 0; j < num; j++) {
      int a;
      cin >> a;
      startkey[0][a] = room;
    }
  }
  link(0, m);
  map<string, int> ends;
  for (int i = 0; i < k; i++) {
    string s;
    cin >> s;
    int room;
    cin >> room;
    ends[s] = room;
    int num;
    cin >> num;
    for (int j = 0; j < num; j++) {
      int a;
      cin >> a;
      startkey[1][a] = room;
    }
  }
  link(1, m);
  bfs(0, n);
  bfs(1, n);
  bool ok1 = true;
  for (map<string, int>::iterator it = name_id.begin();
       it != name_id.end() && ok1; it++) {
    int endroom = ends[(*it).first], startroom = start[(*it).first];
    ok1 = components[0][endroom] == components[0][startroom] &&
          components[1][endroom] == components[1][startroom];
  }
  for (int i = 1; i <= m && ok1; i++) {
    int startroom = startkey[0][i], endroom = startkey[1][i];
    ok1 = components[0][endroom] == components[0][startroom] &&
          components[1][endroom] == components[1][startroom];
  }
  if (ok1)
    cout << "YES";
  else
    cout << "NO";
  return 0;
}
