#include<bits/stdc++.h>
//#include <Windows.h> Sleep(300);
using namespace std;
//#define int long long
#define endl '\n'
#define vi vector<int>
#define pii pair<int, int>
#define pb push_back
#define mod 1000000007
#define log(args...){ string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); cout<<endl; }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
cout << *it << " = " << a << " ";
err(++it, args...);
}
#define fr(i, n) for(int i=0; i<n; i++)
#define fr1(i, n) for(int i=1; i<=n; i++)
#define fab(i, a, b) for(int i=a; i<b; i++)
const int dx[]={+1,-1,+0,+0};
const int dy[]={+0,+0,+1,-1};
int32_t main() {
int t=1; //cin>>t;
while(t--){
int n; cin>>n;
vector<pii> v;
map<int, vi > firstScore;
fr(i, n){int x; cin>>x; v.pb({x, i}); firstScore[x].pb(i); }
int m; cin>>m;
vi replay(m);
fr(i, m){int x; cin>>x; v.pb({x, n+i}); replay[i] = x; }
sort(v.begin(), v.end(), greater<pii>());
int pos = 0;
map<int, vi> ans;
fr(i, m+n) { //log(v[i].first, v[i].second);
//if(replay[i]==v[i].first){
if(firstScore.count(v[i].first)){
int sz = firstScore[v[i].first].size();
i+=sz; i--;
pos+=sz; pos--;
firstScore.erase(v[i].first);
}
else {
//ans[pos++] = i+1;
//cout<<i+1<<" "<<v[i].first<<endl;;
ans[v[i].first].pb(i + 1);
}
//}
}
vi ret;
fr(i, m){
int r = replay[i];
for(auto x: ans[r]) ret.pb(x);
ans.erase(r);
}
fr(i, ret.size()){
cout<<ret[i];
if(i!=ret.size()-1) cout<<" ";
}
}
}