import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); char[] arr = sc.next().toCharArray(); int[] eSums = new int[n + 1]; long[] sSums = new long[n + 1]; for (int i = 1; i <= n; i++) { eSums[i] = eSums[i - 1]; if (arr[i - 1] == 'E') { eSums[i]++; } sSums[i] = sSums[i - 1]; sSums[i] += sc.nextInt(); } int max = eSums[n]; long[] scores = new long[max + 1]; Arrays.fill(scores, Long.MAX_VALUE); scores[0] = 0; for (int i = 0; i < n; i++) { for (int j = i + 1; j <= n; j++) { int count = eSums[j] - eSums[i]; scores[count] = Math.min(scores[count], sSums[j] - sSums[i]); } } int q = sc.nextInt(); StringBuilder sb = new StringBuilder(); for (int i = 0; i < q; i++) { int x = sc.nextInt(); int idx = 0; while (idx < max && scores[idx + 1] <= x) { idx++; } sb.append(idx).append("\n"); } System.out.print(sb); } }