from itertools import accumulate N = int(input()) S = input() E = [int(s == "E") for s in S] A = list(map(int, input().split())) E = [0] + list(accumulate(E)) A = [0] + list(accumulate(A)) task = [] for l in range(N): for r in range(l + 1, N + 1): damage = A[r] - A[l] kill = E[r] - E[l] task.append((damage, ~kill)) Q = int(input()) for i, k in enumerate(map(int, input().split())): task.append((k, i)) task.sort() ans = [-1] * Q MAX = 0 for a, b in task: if b >= 0: ans[b] = MAX else: kill = ~b if kill > MAX: MAX = kill print(*ans, sep="\n")