import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.TreeMap; public class Main { public static void main(String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int n = Integer.parseInt(br.readLine()); char[] s = br.readLine().toCharArray(); String[] sa = br.readLine().split(" "); long[] a = new long[n + 1]; for (int i = 0; i < n; i++) { a[i + 1] = Long.parseLong(sa[i]); } int q = Integer.parseInt(br.readLine()); sa = br.readLine().split(" "); long[] k = new long[q]; for (int i = 0; i < q; i++) { k[i] = Long.parseLong(sa[i]); } br.close(); int[] e = new int[n + 1]; for (int i = 0; i < n; i++) { e[i + 1] = e[i]; if (s[i] == 'E') { e[i + 1]++; } } for (int i = 1; i < a.length; i++) { a[i] += a[i - 1]; } TreeMap map = new TreeMap<>(); map.put(0L, 0); for (int i = 0; i < n; i++) { for (int j = i + 1; j < n + 1; j++) { long b = a[j] - a[i]; if (b > 1000000000) { break; } int c = e[j] - e[i]; if (map.containsKey(b)) { map.put(b, Math.max(c, map.get(b))); } else { map.put(b, c); } } } Long[] arr = map.keySet().toArray(new Long[0]); int v = map.get(arr[0]); for (int i = 1; i < arr.length; i++) { int vi = map.get(arr[i]); if (vi > v) { v = vi; } else { map.remove(arr[i]); } } for (int i = 0; i < q; i++) { System.out.println(map.floorEntry(k[i]).getValue()); } } }