#include <iostream>
#include <fstream>
using namespace std;
int cautare_2(int v[100001],int s,int d,int x,int k){
if(s<d-1){
int m=s+(d-s)/2;
if(x>v[m])
cautare_2(v,m+1,d,x,k);
else if(x<=v[m])
cautare_2(v,s,m,x,k);
}
else{
if(x==v[s])
return s;
else if(x==v[d])
return d;
else
return -1;
}
}
int cautare(int v[100001],int s,int d,int x,int k){
if(s<d-1){
int m=s+(d-s)/2;
if(x>=v[m] && (k==1 || k==0))
cautare(v,m,d,x,k);
else if(x<v[m])
cautare(v,s,m-1,x,k);
else if(x==v[m] && k==2)
cautare_2(v,s,m,x,k);
}
else{
if(x==v[d])
return d;
else if(x==v[s] || k==1)
return s;
else
if(k==0)
return -1;
else if(k==2)
return d;
}
}
int main(){
ifstream f("cautbin.in");
ofstream o("cautbin.out");
int v[100001],n,m,x,k,i;
f>>n;
for(i=1;i<=n;i++)
f>>v[i];
f>>m;
for(i=1;i<=m;i++){
f>>k>>x;
if(k==1 || k==0)
o<<cautare(v,1,n,x,k)<<'\n';
if(k==2)
o<<cautare(v,1,n,x,k)<<'\n';
}
return 0;
}