#include <bits/stdc++.h>
using namespace std;
const int INF = INT_MAX;
const int MAXN = 100005;
int tree[4 * MAXN];
int A[MAXN];
void build(int node, int start, int end) {
if (start == end) {
tree[node] = start;
} else {
int mid = (start + end) / 2;
build(2 * node, start, mid);
build(2 * node + 1, mid + 1, end);
if (A[tree[2 * node]] <= A[tree[2 * node + 1]]) {
tree[node] = tree[2 * node];
} else {
tree[node] = tree[2 * node + 1];
}
}
}
void update(int node, int start, int end, int idx, int value) {
if (start == end) {
A[idx] = value;
tree[node] = start;
} else {
int mid = (start + end) / 2;
if (start <= idx && idx <= mid) {
update(2 * node, start, mid, idx, value);
} else {
update(2 * node + 1, mid + 1, end, idx, value);
}
if (A[tree[2 * node]] <= A[tree[2 * node + 1]]) {
tree[node] = tree[2 * node];
} else {
tree[node] = tree[2 * node + 1];
}
}
}
int query(int node, int start, int end) {
return tree[node];
}
int main() {
int N, Q;
cin >> N;
for (int i = 0; i < N; ++i) {
cin >> A[i];
}
build(1, 0, N - 1);
cin >> Q;
while (Q--) {
int min_pos = query(1, 0, N - 1);
cout << (min_pos + 1) << endl;
int X;
cin >> X;
update(1, 0, N - 1, min_pos, X);
}
return 0;
}