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(); long[] sums = new long[n + 1]; int[] counts = new int[n + 1]; int count = 0; for (int i = 1; i <= n; i++) { sums[i] = sums[i - 1] + sc.nextInt(); if (arr[i - 1] == 'E') { count++; } counts[i] = count; } long[] mins = new long[count + 1]; Arrays.fill(mins, Long.MAX_VALUE); mins[0] = 0; for (int i = 0; i < n; i++) { for (int j = i + 1; j <= n; j++) { int enemy = counts[j] - counts[i]; mins[enemy] = Math.min(mins[enemy], sums[j] - sums[i]); } } int q = sc.nextInt(); StringBuilder sb = new StringBuilder(); for (int i = 0; i < q; i++) { int x = sc.nextInt(); int left = 0; int right = count + 1; while (right - left > 1) { int m = (left + right) / 2; if (mins[m] <= x) { left = m; } else { right = m; } } sb.append(left).append("\n"); } System.out.print(sb); } }