import bisect n = int(input()) s = input() a = [int(i) for i in input().split()] q = int(input()) k = [int(i) for i in input().split()] dp = [10**15]*(n) for i in range(n): cnt = -1 val = 0 for j in range(i,n): if s[j] == "E": cnt += 1 val += a[j] if cnt == -1: continue dp[cnt] = min(dp[cnt],val) #print(cnt,"cnt") #print(dp) #exit() for i in range(q): qry = k[i] tmp = bisect.bisect_right(dp,qry) print(tmp)