#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;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CgojZGVmaW5lIEZFKHgsIHYpIGZvciAodHlwZW9mIHYuYmVnaW4oKSB4ID0gdi5iZWdpbigpOyB4ICE9IHYuZW5kKCk7ICsreCkKI2RlZmluZSBGT1IoaSwgYSwgbikgZm9yKGludCBpID0gYTsgaSA8IChpbnQpbjsgKytpKQojZGVmaW5lIFJFUChpLCBuKSBGT1IoaSwgMCwgbikKI2RlZmluZSBlbCAnXG4nCgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKY29uc3QgaW50IE4gPSAxMDAsIG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