#include <bits/stdc++.h>
using namespace std;
const long double epsilon = 1e-9;
bool keysA[1024][1024];
int componentsA[1024];
map<string, int> namesA;
bool keysB[1024][1024];
int componentsB[1024];
map<string, int> namesB;
int n, m, k;
struct door {
  int x, y, idx;
};
vector<door> ribs;
void solve(bool keys[1024][1024], int components[1024],
           map<string, int>& names) {
  memset(keys, false, sizeof(keys));
  for (int i = 0; i < n; i++) components[i] = i;
  string name;
  int room, numKeys;
  int x;
  for (int i = 0; i < k; i++) {
    cin >> name >> room >> numKeys;
    names[name] = room - 1;
    for (int j = 0; j < numKeys; j++) {
      scanf("%d", &x);
      keys[room - 1][x - 1] = true;
    }
  }
  bool has_changed = true;
  while (has_changed) {
    has_changed = false;
    for (int i = 0; i < m; i++) {
      if (components[ribs[i].x] != components[ribs[i].y] &&
          (keys[components[ribs[i].x]][ribs[i].idx] ||
           keys[components[ribs[i].y]][ribs[i].idx])) {
        has_changed = true;
        if (components[ribs[i].x] > components[ribs[i].y])
          swap(ribs[i].x, ribs[i].y);
        for (int j = 0; j < m; j++)
          keys[components[ribs[i].x]][j] |= keys[components[ribs[i].y]][j];
        int comp = components[ribs[i].y];
        for (int j = 0; j < n; j++)
          if (components[j] == comp) components[j] = components[ribs[i].x];
      }
    }
  }
}
bool equivalent() {
  for (int i = 0; i < n; i++) {
    if (componentsA[i] != componentsB[i]) return false;
    if (i == componentsA[i]) {
      for (int j = 0; j < m; j++) {
        if (keysA[i][j] != keysB[i][j]) return false;
      }
    }
  }
  for (map<string, int>::iterator itr = namesA.begin(); itr != namesA.end();
       ++itr) {
    if (componentsA[itr->second] != componentsB[namesB[itr->first]])
      return false;
  }
  return true;
}
int main() {
  cin >> n >> m >> k;
  ribs.resize(m);
  for (int i = 0; i < m; i++) {
    cin >> ribs[i].x >> ribs[i].y;
    ribs[i].x--;
    ribs[i].y--;
    ribs[i].idx = i;
  }
  solve(keysA, componentsA, namesA);
  solve(keysB, componentsB, namesB);
  if (equivalent()) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
  return 0;
}
