#include <fstream>
using namespace std;
ifstream in("cautbin.in");
ofstream out("cautbin.out");
int t[100005], n, m, i, a, b, c, p, z1, z2, z3, x;
int main()
{
in >> n;
for (i = 1; i <= n; i ++)
in >> t[i];
in >> m;
for (i = 1; i <= m; i ++){
in >> p >> x;
a = 1; b = n;
while (a <= b){
c = (a + b) / 2;
if (p == 0){
if (x == t[c])
z1 = c;
if (x <= t[c])
a = c + 1;
else
b = c - 1;
}
if (p == 1){
if (t[c] <= x)
z2 = c;
if (x <= t[c])
a = c + 1;
else
b = c - 1;
}
if (p == 2){
if (t[c] >= x)
z3 = c;
if (t[c] >= x)
b = c - 1;
else
a = c + 1;
}
}
if (p == 0){
if (z1 == 0)
out << -1;
else
out << z1 << endl;
}
if (p == 1)
out << z2 << endl;
if (p == 2)
out << z3 << endl;
}
return 0;
}