#include <iostream>
#include <vector>
#include <cassert>
#include <algorithm>
using namespace std;
const int MAX = 10000;
int getK(vector<int> a) {
int n = a.size();
int sum = 0;
for (int i = 0; i < n; i++) {
sum += a[i];
}
for (int i = n; i < n * n; i++) {
a.push_back(sum / n);
sum -= a[i - n];
sum += a[i];
}
/*
for (int i = 0; i < n * n; i++) {
fprintf(stderr, "%d ", a[i]);
}
fprintf(stderr, "\n");
*/
int equal = 0;
int len = n;
for (int i = n; i < n * n; i++) {
if (a[i] == a[i - n]) {
equal++;
if (equal >= n) {
len = i;
break;
}
} else {
equal = 0;
}
}
return len;
}
// void test() {
// for (int n = 11; n <= 15; n++) {
// vector<int> a(n);
// for (int i = 0; i < n; i++) {
// a[i] = i + 1;
// }
// int maxK = 0;
// do {
// int K = getK(a);
// maxK = max(maxK, K);
// } while (next_permutation(a.begin(), a.end()));
// fprintf(stderr, "n = %d, maxK = %d\n", n, maxK);
// }
// }
int main() {
int T = 100;
scanf("%d", &T);
assert(T >= 1 && T <= 10);
while (T--) {
int n;
scanf("%d", &n);
assert(n >= 1 && n <= 1000);
vector<int> a(n);
int sum = 0;
for (int i = 0; i < n; i++) {
scanf("%d", &a[i]);
assert(a[i] >= 1 && a[i] <= 1000);
sum += a[i];
}
for (int i = n; i < 2000000; i++) {
a.push_back(sum / n);
sum -= a[i - n];
assert(sum >= 0);
sum += a[i];
}
int Q;
scanf("%d", &Q);
assert(Q >= 1 && Q <= 100000);
while (Q--) {
int K;
scanf("%d", &K);
assert(K >= 1 && K <= (int) 1e9);
K--;
int ans = K < a.size() ? a[K] : a.back();
printf("%d\n", ans);
}
}
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8dmVjdG9yPgojaW5jbHVkZSA8Y2Fzc2VydD4KI2luY2x1ZGUgPGFsZ29yaXRobT4KCnVzaW5nIG5hbWVzcGFjZSBzdGQ7Cgpjb25zdCBpbnQgTUFYID0gMTAwMDA7CgppbnQgZ2V0Syh2ZWN0b3I8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