#include <bits/stdc++.h>
#define nmax 100001
using namespace std;
ofstream fout("cautbin.out");
ifstream fin("cautbin.in");
int n,a[nmax],m;
int CB(int x)
{
int st,dr,mij;
st = 1;
dr = n;
while(st <= dr)
{
mij = (st+dr)/2;
if(a[x] == a[mij]) return mij;
else if(a[x] > a[mij]) st = mij+1;
else if(a[x] < a[mij]) dr = mij-1;
}
return -1;
}
void Solve()
{
int i,op,x,poz;
fin >> n;
for(i = 1; i <= n; i++)
fin >> a[i];
fin >> m;
for(i = 1; i <= m; i++)
{
fin >> op >> x;
poz = CB(x);
if(op == 0)
{
while(a[++poz] == x) ;
poz--;
}
if(op == 1)
{
while(a[++poz] == x) ;
poz--;
}
if(op == 2)
{
while(a[--poz] == x) ;
poz++;
}
fout << poz << "\n";
}
}
int main()
{
Solve();
fin.close();
fout.close();
return 0;
}