n = int(input()) s = input().strip() a = list(map(int, input().split())) q = int(input()) k_values = list(map(int, input().split())) def max_foes_defeated(s, a, k): max_foes = 0 for start in range(n): sharpness = k foes_count = 0 for i in range(start, n): if sharpness >= a[i]: sharpness -= a[i] if s[i] == 'E': foes_count += 1 else: break max_foes = max(max_foes, foes_count) return max_foes for k in k_values: result = max_foes_defeated(s, a, k) print(result)