n = int(input()) a = list(map(int, input().split())) q = int(input()) k = [int(input()) for i in range(q)] ans = [0] ind = [-1] memo = {} for i in range(3 * n): tmp = ans[-1] r = tmp % n if r in memo: lap_length = len(ans) - memo[r] lap_diff = ans[-1] - ans[memo[r] - 1] init_length = len(ans) - lap_length - 1 break memo[r] = len(ans) ans.append(tmp + a[r]) ind.append(r) ru = [0] * (lap_length + 1) for i in range(lap_length): ru[i + 1] = ru[i] + ans[memo[r] + i] - ans[memo[r] - 1 + i] #print(ans) #print(ind) #print(init_length, lap_length, lap_diff) for num in k: if num < len(ans): print(ans[num]) else: res = ans[init_length] laps, rem = divmod(num - res, lap_length) print(res + laps * lap_diff + ru[rem])