#include <iostream>
#include <fstream>
using namespace std;
ifstream in("cautbin.in");
ofstream out("cautbin.out");
int v[100000];
int caut(int n, int x, int a, int b)
{
int pos = (a+b)/2;
if(v[pos] < x)
{
caut(n, x, pos+1, n);
}
else if(x < v[pos])
{
caut(n, x, 0, pos-1);
}
else if(v[pos] == x) return pos;
return -1;
}
int main()
{
int n, m, x, i, c;
in>>n;
for(i=1; i<=n; i++)
in>>v[i];
in>>m;
for(i=1; i<=m; i++)
{
in>>c>>x;
if(c == 0)
{
int nr = caut(n, x, 1, n);
while(v[nr+1] == x) nr++;
out<<nr<<'\n';
}
if(c == 1)
{
if(caut(n, x, 1, n) == -1)
{
while(caut(n, x, 1, n) == -1)
x--;
out<<caut(n, x+1, 1, n)<<'\n';
}
else
{
int nr = caut(n, x, 1, n);
while(v[nr+1] == x) nr++;
out<<nr<<'\n';
}
}
if(c == 2)
{
if(caut(n, x, 1, n) == -1)
{
while(caut(n, x, 1, n) == -1)
x++;
out<<caut(n, x, 1, n);
}
else
{
int nr = caut(n, x, 1, n);
while(v[nr-1] == x) nr--;
out<<nr<<'\n';
}
}
}
return 0;
}