#include <bits/stdc++.h>
using namespace std;
const long double pi = 3.141592653589793238462643;
int n, m, k;
int was[2000];
int p[2000];
int p2[2000];
set<int> cl[2000];
set<int> cl2[2000];
pair<int, int> g[2000];
map<string, int> ma1, ma2;
int get(int x) {
  if (x == p[x]) return x;
  p[x] = get(p[x]);
  for (auto o : cl[x]) {
    cl[p[x]].insert(o);
  }
  cl[x].clear();
  return p[x];
}
void add(int x, int y) {
  x = get(x);
  y = get(y);
  if (x == y) return;
  p[x] = y;
  for (auto o : cl[x]) {
    cl[y].insert(o);
  }
  cl[x].clear();
}
int get2(int x) {
  if (x == p2[x]) return x;
  p2[x] = get2(p2[x]);
  for (auto o : cl2[x]) {
    cl2[p2[x]].insert(o);
  }
  cl2[x].clear();
  return p2[x];
}
void add2(int x, int y) {
  x = get2(x);
  y = get2(y);
  if (x == y) return;
  p2[x] = y;
  for (auto o : cl2[x]) {
    cl2[y].insert(o);
  }
  cl2[x].clear();
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m >> k;
  for (int i = 0; i < (m); i++) {
    int x, y;
    cin >> x >> y;
    x--;
    y--;
    g[i] = make_pair(x, y);
  }
  for (int i = 0; i < (k); i++) {
    string s;
    cin >> s;
    int y;
    cin >> y;
    y--;
    int t;
    cin >> t;
    ma1[s] = y;
    for (int j = 0; j < (t); j++) {
      int x;
      cin >> x;
      x--;
      cl[y].insert(x);
    }
  }
  for (int i = 0; i < n; i++) p[i] = i;
  for (int i = 0; i < (n); i++) {
    if (i != get(i)) continue;
    int cur = 0;
    while (cur < n + 5)
      for (int j = 0; j < m; j++) {
        int x = get(g[j].first);
        int y = get(g[j].second);
        if (cl[i].find(j) != cl[i].end()) {
          if (x == i && y != i) {
            add(y, i);
            cur = 0;
          }
          if (x != i && y == i) {
            add(x, i);
            cur = 0;
          }
        }
        cur++;
      }
  }
  for (int i = 0; i < (k); i++) {
    string s;
    cin >> s;
    int y;
    cin >> y;
    y--;
    int t;
    cin >> t;
    ma2[s] = y;
    for (int j = 0; j < (t); j++) {
      int x;
      cin >> x;
      x--;
      cl2[y].insert(x);
    }
  }
  for (int i = 0; i < n; i++) p2[i] = i;
  for (int i = 0; i < (n); i++) {
    if (i != get2(i)) continue;
    int cur = 0;
    while (cur < n + 5)
      for (int j = 0; j < m; j++) {
        int x = get2(g[j].first);
        int y = get2(g[j].second);
        if (cl2[i].find(j) != cl2[i].end()) {
          if (x == i && y != i) {
            add2(y, i);
            cur = 0;
          }
          if (x != i && y == i) {
            add2(x, i);
            cur = 0;
          }
        }
        cur++;
      }
  }
  for (int i = 0; i < (n); i++) {
    int x = get(i);
    int y = get2(i);
    if (cl[x] != cl2[y]) {
      cout << "NO";
      return 0;
    }
  }
  for (auto o : ma1) {
    string x = o.first;
    if (get(ma1[x]) != get(ma2[x])) {
      cout << "NO";
      return 0;
    }
  }
  cout << "YES";
  return 0;
}
