#pragma GCC optimize("O3")
#define _CRT_SECURE_NO_WARNINGS
#define _SILENCE_CXX17_C_HEADER_DEPRECATION_WARNING
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e6 + 50;
int a[N], b[N];
int main()
{
    int n, q;
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) scanf("%d", a + i);
    for (int i = 1; i <= n; i++) scanf("%d", b + i);
    auto mm = minmax_element(b + 1, b + n + 1);
    int rg = sqrt(*mm.second - *mm.first) / 4, po = 1;
    scanf("%d", &q);
    ll inf;
    memset(&inf, 0x3f, sizeof(inf));
    while (q--)
    {
        int x;
        scanf("%d", &x);
        ll mx = inf;
        while (a[po] < x && po <= n) po++;
        int st = max(1, po - rg), ed = min(n, po + rg);
        for (int i = st; i <= ed; i++)
            mx = min(mx, 1ll * (x - a[i]) * (x - a[i]) + b[i]);
        printf("%lld ", mx);
    }
    return 0;
}
