#include <bits/stdc++.h>
using namespace std;
int n, m, a[100005], b;
int main()
{
cin >> n;
for (int i = 1; i <= n; i++)
scanf("%d", a + i);
cin >> m;
while (m--)
{
scanf("%d", &b);
int l = 1, r = n;
int ans = 1;
while (l <= r)
{
int mid = l + r >> 1;
if (a[mid] <= b)
{
ans = mid;
l = mid + 1;
}
else
r = mid - 1;
}
if (a[ans] == b || abs(a[ans] - b) <= abs(a[ans + 1] - b))
cout << a[ans] << endl;
else
cout << a[ans + 1] << endl;
}
return 0;
}