# include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define mod 1000000007
void dfs(vector <vector<ll>> &graph,vector <bool> &visited,ll i)
{
visited[i]=true;
for(auto x: graph[i])
{
if(!visited[x])
dfs(graph,visited,x);
}
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll t,i,j,k,n;
cin>>n;
map <ll,ll> m;
for(i=0;i<n;i++)
{
cin>>j;
m[j]=i;
}
ll q;
cin>>q;
vector <vector<ll>> graph(n);
while(q--)
{
ll x1,x2;
cin>>x1>>x2;
graph[m[x1]].push_back(m[x2]);
//graph[m[x2]].push_back(m[x1]);
}
ll x1,x2;
cin>>x1>>x2;
x1=m[x1];
x2=m[x2];
vector <bool> visited(n,false);
dfs(graph,visited,x1);
if(visited[x2])
cout<<"1"<<endl;
else
cout<<"0"<<endl;
}
ICMgaW5jbHVkZSA8Yml0cy9zdGRjKysuaD4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKI2RlZmluZSBsbCBsb25nIGxvbmcgaW50CiNkZWZpbmUgbW9kIDEwMDAwMDAwMDcKCnZvaWQgZGZzKHZlY3RvciA8dmVjdG9yPGxsPj4gJmdyYXBoLHZlY3RvciA8Ym9vbD4gJnZpc2l0ZWQsbGwgaSkKewogICAgdmlzaXRlZFtpXT10cnVlOwogICAgZm9yKGF1dG8geDogZ3JhcGhbaV0pCiAgICB7CiAgICAgICAgaWYoIXZpc2l0ZWRbeF0pCiAgICAgICAgICAgIGRmcyhncmFwaCx2aXNpdGVkLHgpOwogICAgfQp9CmludCBtYWluKCkKewogICAgaW9zX2Jhc2U6OnN5bmNfd2l0aF9zdGRpbyhmYWxzZSk7CiAgICBjaW4udGllKE5VTEwpOwogICAgbGwgdCxpLGosayxuOwogICAgY2luPj5uOwogICAgbWFwIDxsbCxsbD4gbTsKICAgIGZvcihpPTA7aTxuO2krKykKICAgIHsKICAgICAgICBjaW4+Pmo7CiAgICAgICAgbVtqXT1pOwogICAgfQogICAgbGwgcTsKICAgIGNpb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