#include <bits/stdc++.h>
using namespace std;
const int MAXPEP = 1000;
const int MAXDOOR = 1000;
const int MAXROOM = 1000;
char name[2][MAXPEP + 10][15];
int st[MAXDOOR + 10], ed[MAXDOOR + 10];
int r[2][MAXPEP + 10];
int who[2][MAXDOOR + 10];
int roomN, doorN, pepN;
int f[2][MAXROOM + 10];
int main() {
  scanf("%d%d%d", &roomN, &doorN, &pepN);
  for (int i = 1; i <= doorN; i++) {
    scanf("%d%d", &st[i], &ed[i]);
  }
  for (int t = 0; t < 2; t++) {
    for (int i = 1; i <= pepN; i++) {
      int keyN;
      scanf("%s%d%d", name[t][i], &r[t][i], &keyN);
      for (int j = 1; j <= keyN; j++) {
        int x;
        scanf("%d", &x);
        who[t][x] = i;
      }
    }
    for (int i = 1; i <= roomN; i++) f[t][i] = i;
    while (true) {
      bool done = true;
      for (int i = 1; i <= doorN; i++) {
        int fA = f[t][st[i]];
        int fB = f[t][ed[i]];
        if (fA != fB) {
          int fC = f[t][r[t][who[t][i]]];
          if (fA == fC || fB == fC) {
            done = false;
            if (fB == fC) swap(fA, fB);
            for (int j = 1; j <= roomN; j++)
              if (f[t][j] == fB) f[t][j] = fA;
          }
        }
      }
      if (done) break;
    }
  }
  map<string, int> name2r;
  for (int i = 1; i <= pepN; i++) name2r[name[0][i]] = r[0][i];
  for (int i = 1; i <= pepN; i++) {
    int x = name2r[name[1][i]];
    int y = r[1][i];
    if (f[0][x] != f[0][y] || f[1][x] != f[1][y]) {
      puts("NO");
      return 0;
    }
  }
  for (int i = 1; i <= doorN; i++) {
    int x = r[0][who[0][i]];
    int y = r[1][who[1][i]];
    if (f[0][x] != f[0][y] || f[1][x] != f[1][y]) {
      puts("NO");
      return 0;
    }
  }
  puts("YES");
  return 0;
}
