#include<bits/stdc++.h>
using namespace std;

int N;
int X[111];
int M;
int A[11],B[11],C[11];

int dp[111][111][11];
int solve(int l,int r,int id){
  if( dp[l][r][id]!=-1) return dp[l][r][id];
  int fl = 0;
  if( r-l == 1 ) {
    if(A[id] ==X[l]) return dp[l][r][id] = 1;
    return dp[l][r][id] = 0;
  }
  for(int i=l+1;i<r;i++){
    if( solve( l,i,B[id] ) && solve( i, r, C[id] ) ){
      fl = 1; continue;
    }
  }
  return dp[l][r][id] = fl;
}

int main(){
  memset( dp,-1,sizeof(dp));
  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];
  }
  if( solve(0,N,0) ) cout << "Yes" << endl;
  else cout << "No" << endl;
}