/*
 * d.cc: 
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>

using namespace std;

/* constant */

const int MAX_N = 100;
const int MAX_M = 10;

typedef long long ll;

const int INF = 1 << 30;
const ll LINF = 1LL << 60;

/* typedef */

typedef vector<int> vi;
typedef queue<int> qi;
typedef pair<int,int> pii;

/* global variables */

int xs[MAX_N], as[MAX_M], bs[MAX_M], cs[MAX_M];
bool dp[MAX_M][MAX_N][MAX_N];

/* subroutines */

/* main */

int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) cin >> xs[i];

  int m;
  cin >> m;
  for (int i = 0; i < m; i++) {
    cin >> as[i] >> bs[i] >> cs[i];
    bs[i]--, cs[i]--;
  }

  for (int i = 0; i < m; i++)
    for (int j = 0; j < n; j++)
      dp[i][j][j] = (as[i] == xs[j]);

  for (int l = 1; l < n; l++)
    for (int i = 0; i < m; i++)
      for (int j0 = 0, j1 = l; j1 < n; j0++, j1++) {
	dp[i][j0][j1] = false;
	for (int k = j0; k < j1; k++)
	  if (dp[bs[i]][j0][k] && dp[cs[i]][k + 1][j1]) {
	    dp[i][j0][j1] = true;
	    break;
	  }
      }

  cout << (dp[0][0][n - 1] ? "Yes" : "No") << endl;
  return 0;
}