import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines import numpy as np N = int(readline()) S = np.frombuffer(readline().rstrip(),'S1') == b'E' A = np.array(readline().split(),np.int64) Q = int(readline()) K = np.array(read().split(),np.int64) INF = 10 ** 18 min_power = [INF] * (N+1) for L in range(N): power = A[L:].cumsum() n_enemy = np.cumsum(S[L:]) for p,n in zip(power.tolist(), n_enemy.tolist()): if min_power[n] > p: min_power[n] = p for n in range(N-1,-1,-1): if min_power[n] > min_power[n+1]: min_power[n] = min_power[n+1] answer = np.searchsorted(min_power, K, 'right') - 1 print('\n'.join(answer.astype(str)))