#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> PII;
const ll mx = 3e5+10;
int arr[mx];
int tree[mx * 3];
void init(int node, int b, int e) {
if(b == e) {
tree[node] = arr[b];
return;
}
int Left = node * 2;
int Right = node * 2 + 1;
int mid = (b + e) / 2;
init(Left, b, mid);
init(Right, mid + 1, e);
tree[node] = min(tree[Left], tree[Right]);
}
int query(int node, int b, int e, int i, int j) {
if(i > e || j < b)
return LONG_MAX;
if(b >= i && e <= j)
return tree[node];
int Left = node * 2;
int Right = node * 2 + 1;
int mid = (b + e) / 2;
int p1 = query(Left, b, mid, i, j);
int p2 = query(Right, mid + 1, e, i, j);
return min(p1, p2);
}
void update(int node, int b, int e, int i, int newvalue) {
if(i > e || i < b)
return;
if(b >= i && e <= i) {
tree[node] = newvalue;
return;
}
int Left = node * 2;
int Right = node * 2 + 1;
int mid = (b + e) / 2;
update(Left, b, mid, i, newvalue);
update(Right, mid + 1, e, i, newvalue);
tree[node] = min(tree[Left], tree[Right]);
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(nullptr);
cout.tie(nullptr);
int n;
cin>> n;
map<ll,ll> Mp;
for(int i=1;i<=n;i++) {
cin >> arr[i];
Mp[arr[i]] = i;
}
init(1,1,n);
int q;
cin >> q;
while(q--) {
ll num;
cin >> num;
ll Ans = query(1,1,n, 1, n);
cout<<Mp[Ans]<<"\n";
update(1,1,n, Mp[Ans], num);
Mp[Ans] = -1;
}
}