N = int(input()) S = input() A = list(map(int,input().split())) teki = [0] * (N + 1) for i in range(N): teki[i+1] = teki[i] if S[i] == "E": teki[i+1] += 1 def calc(k): right = 0 now = 0 ans = 0 for left in range(N): while right < N and now + A[right] <= k: now += A[right] right += 1 count = teki[right] - teki[left] if count > ans: ans = count if left == right: right += 1 else: now -= A[left] return ans Q = int(input()) K = list(map(int,input().split())) for k in K: print(calc(k))