#include <bits/stdc++.h>

#define FE(x, v) for (typeof v.begin() x = v.begin(); x != v.end(); ++x)
#define FOR(i, a, n) for(int i = a; i < (int)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define el '\n'

using namespace std;

const int N = 100, oo = 1000000000;
int n, x, y, a, b, g1[N][N], g2[N][N];
string s;
bool v, p;

int main() {
  ios_base::sync_with_stdio(false); cin.tie(NULL);
  while (cin >> n && n) {
    REP(i, n) REP(j, n) g1[i][j] = g2[i][j] = (i == j) ? 0 : oo;
    if (p) cerr << "Normal:" << el;
    REP(nn, n) {
      cin >> x; --x;
      getline(cin, s);
      istringstream iss(s);
      while (iss >> y) { 
		g1[x][--y] = 1;
		if (p) cerr << x+1 << "->" << y+1 << ' ';
      }
      if (p) cerr << el;
    }
    if (p) cerr << el << "Prop:" << el;
    REP(nn, n) {
      cin >> x; --x;
      getline(cin, s);
      istringstream iss(s);
      while (iss >> y) {
		g2[x][--y] = 1;
		if (p) cerr << x+1 << "->" << y+1 << ' ';
      }
      if (p) cerr << el;
    }
    if (p) cerr << el;
    cin >> a >> b;
    REP(k, n) REP(i, n) REP(j, n) {
      g1[i][j] = min(g1[i][j], g1[i][k] + g1[k][j]);
      g2[i][j] = min(g2[i][j], g2[i][k] + g2[k][j]);
    }
    v = true;
    REP(i, n) {
      if (!v) break;
      REP(j, n) 
		if (g2[i][j] > (g1[i][j] * a + b)) {
	  		v = false;
	  		break;
		}
    }
    cout << (v ? "Yes\n" : "No\n");
  }
  return 0;
}