#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;

int n,m,memo[110][110][11];
vector<int> x,a,b,c;

int rec(int l, int r, int k){
  if(memo[l][r][k])return memo[l][r][k];
  if(r<=l)return -1;
  if(r-l==1)return (x[l] == a[k]) ? 1 : -1;
  
  int res = -1;
  for(int m=l+1;m<r;m++){
    if(rec(l,m,b[k])>0 && rec(m,r,c[k])>0){
      res = 1;
      break;
    }
  }

  return memo[l][r][k] = res;
}

int main(){
  cin >> n;
  x.resize(n);
  rep(i,n)cin >> x[i];
  cin >> m;
  a = b = c = vector<int>(m);
  rep(i,m){
    cin >> a[i] >> b[i] >> c[i];
    b[i]--; c[i]--;
  }

  memset(memo,0,sizeof(memo));
  cout << (rec(0,n,0)>0 ? "Yes" : "No") << endl;
}