#include <iostream>
#include <string.h>
#include <fstream>
using namespace std;
ifstream in("cautbin.in");
ofstream out("cautbin.out");
int n, m, v[100001], w[100001];
int lower_bound(int x)
{
int st=1, dr=n;
int aux;
while(st<=dr)
{
int mij=(st+dr)/2;
if(v[mij]<=x)
{
aux=mij;
st=mij+1;
}
else dr=mij-1;
}
return aux;
}
int upper_bound(int x)
{
int st=1, dr=n;
int aux;
while(st<=dr){
int mij=(st+dr)/2;
if(v[mij]>=x)
{
aux=mij;
dr=mij-1;
}
else
st=mij+1;
}
}
int main()
{
in>>n;
for(int i=1; i<=n; i++)
in>>v[i];
in>>m;
for(int i=1; i<=m; i++)
{
int a, b;
in>>a>>b;
if(a==1) w[i]=lower_bound(b);
else if(a==2) w[i]=upper_bound(b);
else{
int x=lower_bound(b);
if(v[x]!=b) w[i]=-1;
else w[i]=x;
}
}
for(int i=1; i<=m; i++)
out<<w[i]<<"\n";
return 0;
}