#include #include #include #include #include #include #include #include #include #include #include #include #define vll vector #define vvvl vector #define vvl vector> #define VV(a, b, c, d) vector>(a, vector(b, c)) #define VVV(a, b, c, d) vector(a, vvl(b, vll (c, d))); #define re(c, b) for(ll c=0;c> n; string s;std::cin >> s; vll a(n);get(a); vvl cost = VV(n, n+1, 0, ll); vvl num = VV(n, n+1, 0, ll); for(int i=0;in) cost[i][j] = INF; else { cost[i][j] = cost[i][j-1] + a[i+j-1]; num[i][j] = (s[i+j-1]=='E'?1:0) + num[i][j-1]; } } } ll q;std::cin >> q; re(T, q){ ll t;std::cin >> t; ll ans = 0; for(int i=0;i