#include <bits/stdc++.h>
using namespace std;using ll=int_fast64_t;using ld=long double;using pll=pair<ll,ll>;using pld=pair<ld,ld>;
const ll INF=1LL<<60;void solve();int main(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(10);solve();}
#define foreach(i,a) for(auto &i:a)
#define SELECTOR(_1,_2,_3,_4,SELECT,...) SELECT
#define rep(...) SELECTOR(__VA_ARGS__,_rep2,_rep1,_rep0)(__VA_ARGS__)
#define _rep0(i,n) for(ll i=0;i<n;++i)
#define _rep1(i,k,n) for(ll i=k;i<n;++i)
#define _rep2(i,k,n,d) for(ll i=k;d!=0&&d>0?i<n:i>n;i+=d)
template<class T> vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
template<class... Ts> auto make_v(size_t a,Ts... ts){return vector<decltype(make_v(ts...))>(a,make_v(ts...));}
template<class T> inline bool chmax(T &a,const T &b){if(a<b){a=b; return 1;} return 0;}
template<class T> inline bool chmin(T &a,const T &b){if(a>b){a=b; return 1;} return 0;}

void solve(){
  ll n; cin>>n;
  string S; cin>>S;
  ll q; cin>>q;
  rep(_,q){
    ll k; cin>>k;
    vector<ll> DMC(3);
    ll cnt=0;
    ll ans=0;
    queue<char> Q;
    foreach(s,S){
      // push
      if(s=='D'){
        DMC[0]++;
      }else if(s=='M'){
        DMC[1]++;
        cnt+=DMC[0];
      }else if(s=='C'){
        DMC[2]++;
        ans+=cnt;
      }
      Q.push(s);

      // pop
      if(Q.size()<k) continue;
      char t=Q.front(); Q.pop();
      if(t=='D'){
        DMC[0]--;
        cnt-=DMC[1];
      }else if(t=='M'){
        DMC[1]--;
      }else if(t=='C'){
        DMC[2]--;
      }
    }
    cout<<ans<<"\n";
  }
}
#include <cstdio>
#include <iostream>
#include <vector>
#include <set>
using namespace std;

#define M 100000

vector<int> G[M];
int N;
bool visited[M];
int prenum[M], parent[M], lowest[M], timer;

void dfs(int current, int prev){
  //?????????current????¨???????????????¨?????????
  prenum[current] = lowest[current] = timer;
  timer++;

  visited[current] = true;

  int next;
  for(int i=0; i<G[current].size(); ++i){
    next = G[current][i];

    if( !visited[next] ){
      //?????????current???????????????next????¨????????????´????????????
      parent[next] = current;

      dfs(next, current);

      //?????????next?????¢?´¢????????????????????¨?????????
      lowest[current] = min(lowest[current], lowest[next]);
    }
    else if( next != prev){ //??¨??????current --> next ???Back-Edge?????´???
      lowest[current] = min(lowest[current], prenum[next]);
    }

  }
  //?????????current ?????¢?´¢????????????????????¨?????????
}

void art_points(){
  for(int i=0; i<N; ++i) visited[i] = false;
  timer=1;

  //lowest????¨????
  dfs(0, -1); //0 == root

  set<int> ap;
  int np=0;
  for(int i=1; i<N; ++i){
    int p = parent[i];
    if(p==0) np++;
    else if(prenum[p] <= lowest[i]) ap.insert(p);
  }

  if(np>1) ap.insert(0);
  for(set<int>::iterator it = ap.begin(); it!=ap.end(); ++it) cout << *it << endl;
}

int main(){
  int m;
  scanf(" %d %d", &N, &m);

  for(int i=0; i<m; ++i){
    int s, t;
    scanf(" %d %d", &s, &t);
    G[s].push_back(t);
    G[t].push_back(s);
  }

  art_points();

}