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)) Q = int(input()) for k in map(int, input().split()): ans = 0 r = 0 for l in range(N): r = max(l, r) while r + 1 <= N and A[r + 1] - A[l] <= k: r += 1 ans = max(ans, E[r]-E[l]) print(ans)