#ifdef LOCAL
#include <local.hpp>
#else
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,popcnt,lzcnt,abm,bmi,bmi2")
#include <bits/stdc++.h>
#define debug(...) ((void)0)
#define postprocess(...) ((void)0)
#endif

#include <atcoder/fenwicktree.hpp>

using namespace std;
using ll = long long;
using ld = long double;

void solve([[maybe_unused]] int test) {
    int N, Q;
    cin >> N >> Q;

    string S;
    cin >> S;

    atcoder::fenwick_tree<ll> fwt_x(2 * N), fwt_y(2 * N);
    for (int i = 0; i < N; i++) {
        if (S[i] == 'D') {
            fwt_x.add(i, 1);
            fwt_x.add(i + N, 1);
        } else {
            fwt_y.add(i, 1);
            fwt_y.add(i + N, 1);
        }
    }

    for (int q = 0; q < Q; q++) {
        ll H, W, P;
        cin >> H >> W >> P;

        ll imin = 0;
        ll imax = H + W;

        while (imax - imin > 1) {
            ll imid = (imin + imax) / 2;

            ll loop = imid / N;
            pair<ll, ll> cur = {
                loop * fwt_x.sum(0, N),
                loop * fwt_y.sum(0, N),
            };

            cur.first += fwt_x.sum(P, P + imid % N);
            cur.second += fwt_y.sum(P, P + imid % N);

            if (cur.first >= H || cur.second >= W) {
                imax = imid;
            } else {
                imin = imid;
            }
        }

        cout << (P + imax) % N << endl;
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int t = 1;
    // cin >> t;
    for (int i = 1; i <= t; i++) {
        solve(i);
    }

    postprocess();
}