#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back
#define INF (1e9+1)
//#define INF (1LL<<59)

int main(){
	int n;
	cin>>n;
	vector<int> v(n);
	rep(i,n)cin>>v[i];
	
	int m;
	cin>>m;
	vector<int> mp(m);
	vector<pii> call(m);
	rep(i,m){
		int b,c;
		cin>>mp[i]>>b>>c;
		b--,c--;
		call[i] = pii(b,c);
	}
	
	bool dp[100][100][10];
	memset(dp,0,sizeof(dp));
	
	rep(i,n){
		rep(j,mp.size()){
			if(v[i]==mp[j]){
				dp[i][i][j]=true;
			}
		}
	}
	
	for(int width = 2; width<=n; width++){
		for(int l = 0; l<n; l++){
			int r = l+width-1;
			if(r>=n)continue;
			for(int i=0;i<m;i++){
				int x,y;
				tie(x,y) = call[i];
				for(int p=l; p<=r-1; p++){
					dp[l][r][i] |= (dp[l][p][x] & dp[p+1][r][y]);
				}
			}
		}
	}
	if(dp[0][n-1][0])cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}