#include <iostream>
using namespace std;
int N, M, a[15], b[15], c[15], x[109]; bool vis[15][109][109], dp[15][109][109];
bool solve(int pos, int l, int r) {
	if (r - l == 1) return x[l] == a[pos];
	if (vis[pos][l][r]) return dp[pos][l][r];
	for (int i = l + 1; i <= r - 1; ++i) {
		if (solve(b[pos], l, i) && solve(c[pos], i, r)) {
			dp[pos][l][r] = true;
		}
	}
	vis[pos][l][r] = true;
	return dp[pos][l][r];
}
int main() {
	cin >> N;
	for (int i = 0; i < N; ++i) cin >> x[i];
	cin >> M;
	for (int i = 0; i < M; ++i) cin >> a[i] >> b[i] >> c[i], --b[i], --c[i];
	bool ans = solve(0, 0, N);
	cout << (ans ? "Yes" : "No") << endl;
	return 0;
}
