#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;
int main() {
int n;
cin >> n;
vector<int> a(n);
priority_queue<pii, vector<pii>, greater<pii>> minHeap;
for (int i = 0; i < n; ++i) {
cin >> a[i];
minHeap.push({a[i], i});
}
int q;
cin >> q;
for (int i = 0; i < q; ++i) {
int x;
cin >> x;
while (minHeap.top().first != a[minHeap.top().second]) {
minHeap.pop();
}
pii minElement = minHeap.top();
minHeap.pop();
cout << minElement.second + 1 << endl;
a[minElement.second] = x;
minHeap.push({x, minElement.second});
}
return 0;
}