#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef pair<ll, ll> PLL;
#define chmax(x, y) do { x = max(x, y); } while(0)
#define chmin(x, y) do { x = min(x, y); } while(0)
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) \
  for (ll i = static_cast<ll>(a); i < static_cast<ll>(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, ) (__VA_ARGS__)  // NOLINT
template<typename T>
using reversed_priority_queue = std::priority_queue<T, std::vector<T>, std::greater<T> >;

ll N, Q;
string s;

signed main() {
  cin >> N >> s >> Q;
  while (Q--) {
    ll k;
    cin >> k;
    vector<ll> d(N, 0), m(N, 0), dm(N, 0);
    // d, m, dm の構築
    if (s[0] == 'D') d[0] = 1;
    if (s[0] == 'M') m[0] = 1;
    for (int i = 1; i < N; i++) {
      d[i] = d[i-1];
      m[i] = m[i-1];
      dm[i] = dm[i-1];
      if (s[i] == 'D') {
        d[i] += 1;
      }
      if (s[i] == 'M') {
        m[i] += 1;
        dm[i] += d[i-1];
      }
    }
    ll ans = 0;
    // 集計
    for (int i = 2; i < N; i++) {
      if (s[i] != 'C') continue;
      ans += dm[i-1];
      if (i - k >= 0) {
        ans -= dm[i-k];
        ans -= d[i-k] * (m[i-1] - m[i-k]);
      }
    }
    cout << ans << endl;
  }
  return 0;
}

#include <bits/stdc++.h>
using namespace std;
 
template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &vec){ os << "["; for (auto v : vec) os << v << ", "; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const deque<T> &vec){ os << "deq["; for (auto v : vec) os << v << ", "; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const set<T> &vec){ os << "{"; for (auto v : vec) os << v << ", "; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_set<T> &vec){ os << "{"; for (auto v : vec) os << v << ", "; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ", "; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ", "; os << "}"; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &pa){ os << "(" << pa.first << ", " << pa.second << ")"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << ": " << v.second << ", "; os << "}"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const unordered_map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << ": " << v.second << ", "; os << "}"; return os; }
template<typename T> void ndarray(vector<T> &vec, int len) { vec.resize(len); }
template<typename T, typename... Args> void ndarray(vector<T> &vec, int len, Args... args) { vec.resize(len); for (auto &v : vec) ndarray(v, args...); }
template<typename T> bool chmax(T &m, const T q) { if (m < q) {m = q; return true;} else return false; }
template<typename T> bool chmin(T &m, const T q) { if (q < m) {m = q; return true;} else return false; }
template<typename T1, typename T2> pair<T1, T2> operator+(const pair<T1, T2> &l, const pair<T1, T2> &r) { return make_pair(l.first + r.first, l.second + r.second); }
template<typename T1, typename T2> pair<T1, T2> operator-(const pair<T1, T2> &l, const pair<T1, T2> &r) { return make_pair(l.first - r.first, l.second - r.second); }
#define f first
#define s second
 
void printer(char c, int dist) {
    for(int i = 0; i < dist; i++)
        cout << c;
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int x, y, endx, endy;
    cin >> x >> y >> endx >> endy;
    int distx = abs(endx - x), disty = abs(endy - y);
    printer('U', disty);
    printer('R', distx);
    printer('D', disty);
    printer('L', distx);
    cout << 'L';
    printer('U', disty + 1);
    printer('R', distx + 1);
    cout << "DR";
    printer('D', disty + 1);
    printer('L', distx + 1);
    cout << 'U';
}