#include <fstream>
using namespace std;
ifstream fin("cautbin.in");
ofstream fout("cautbin.out");
int main() {
int n, v[100001];
fin >> n;
for (int i = 0; i < n; i++) {
fin >> v[i];
}
int m;
fin >> m;
for (int i = 0; i < m; i++) {
int x, cer;
fin >> cer >> x;
int st = 0, dr = n - 1, poz = -1;
if (cer == 0 || cer == 1) {
while (st <= dr) {
int mij = st + (dr - st) / 2;
if (v[mij] <= x) {
poz = mij;
st = mij + 1;
} else {
dr = mij - 1;
}
}
if (cer == 0 && (poz == -1 || v[poz] != x)) {
fout << -1 << '\n';
} else {
fout << poz + 1 << '\n';
}
} else if (cer == 2) {
while (st <= dr) {
int mij = st + (dr - st) / 2;
if (v[mij] >= x) {
poz = mij;
dr = mij - 1;
} else {
st = mij + 1;
}
}
fout << poz + 1 << '\n';
}
}
return 0;
}