#include <fstream>
#include <algorithm>
#include <vector>
using namespace std;
ifstream cin("cautbin.in");
ofstream cout("cautbin.out");
int main()
{
int n, m;
cin >> n;
vector<int> v(n);
for (int i = 0; i < n; i++)
{
cin >> v[i];
}
cin >> m;
while (m--)
{
int t, val;
cin >> t >> val;
if (t == 0)
{
auto it = upper_bound(v.begin(), v.end(), val);
if (it != v.begin() && *(it - 1) == val)
cout << (it - v.begin()) << '\n';
else
cout << -1 << '\n';
}
else if (t == 1)
{
auto it = upper_bound(v.begin(), v.end(), val);
if (it != v.begin())
cout << (it - v.begin()) << '\n';
else
cout << -1 << '\n';
}
else if (t == 2)
{
auto it = lower_bound(v.begin(), v.end(), val);
if (it != v.end())
cout << (it - v.begin() + 1) << '\n';
else
cout << n + 1 << '\n';
}
}
return 0;
}