#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
int n; cin >> n;
long long a[n+1];
a[0]=-1;
for(int i=1;i<=n;i++) cin >> a[i];
sort(a+1,a+n+1);
int q; cin >> q;
while(q--) {
long long x; cin >> x;
int j=upper_bound(a+1,a+n+1,x)-a;
if(j==n+1 || a[j]>x) j--;
cout << a[j] << '\n';
}
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CmludCBtYWluKCkgewogICAgaW9zOjpzeW5jX3dpdGhfc3RkaW8oZmFsc2UpOwogICAgY2luLnRpZSgwKSwgY291dC50aWUoMCk7CiAgICBpbnQgbjsgY2luID4+IG47CiAgICBsb25nIGxvbmcgYVtuKzFdOwogICAgYVswXT0tMTsKICAgIGZvcihpbnQgaT0xO2k8PW47aSsrKSBjaW4gPj4gYVtpXTsKICAgIHNvcnQoYSsxLGErbisxKTsKICAgIGludCBxOyBjaW4gPj4gcTsKICAgIHdoaWxlKHEtLSkgewogICAgICAgIGxvbmcgbG9uZyB4OyBjaW4gPj4geDsKICAgICAgICBpbnQgaj11cHBlcl9ib3VuZChhKzEsYStuKzEseCktYTsKICAgICAgICBpZihqPT1uKzEgfHwgYVtqXT54KSBqLS07CiAgICAgICAgY291dCA8PCBhW2pdIDw8ICdcbic7CiAgICB9CiAgICByZXR1cm4gMDsKfQ==