MOD = 10 ** 9 + 7 INF = 10 ** 10 import sys sys.setrecursionlimit(100000000) dy = (-1,0,1,0) dx = (0,1,0,-1) from collections import deque from heapq import heapify,heappush,heappop from copy import deepcopy def main(): n = int(input()) s = input() a = list(map(int,input().split())) q = int(input()) query = list(map(int,input().split())) for index in range(q): t = query[index] r = 0 tot = 0 ans = 0 cnt = 0 for l in range(n): while r < n and tot + a[r] <= t: if s[r] == 'E': cnt += 1 tot += a[r] r += 1 ans = max(ans,cnt) if l == r: r += 1 cnt = 0 tot = 0 else: if s[l] == 'E': cnt -= 1 tot -= a[l] print(ans) if __name__ == '__main__': main()