#include using namespace std; using ll = long long; #define rep(i, n) for (int i = 0; i < (int)(n); i++) void solve() { ll n, q; string s; cin >> n >> q >> s; vector sum(2, vector(n + 1, 0)); vector pos(2, vector(n, -1)); rep(i, n) { rep(j, 2) { sum[j][i + 1] = sum[j][i]; if ((j == 0 && s[i] == 'D') || (j == 1 && s[i] == 'R')) { sum[j][i + 1] += 1; pos[j][sum[j][i]] = i; } } } rep(qi, q) { vector hw(2); ll op; cin >> hw[0] >> hw[1] >> op; ll ans = 1e18; rep(qj, 2) { if (sum[qj][n] == 0) continue; ll p = op; ll len = hw[qj] - 1; ll res = n * (len / sum[qj][n]); len %= sum[qj][n]; len += 1; if (len > sum[qj][n] - sum[qj][p]) { len -= sum[qj][n] - sum[qj][p]; res += n - p; p = 0; } res += pos[qj][sum[qj][p] + len - 1] - p + 1; ans = min(ans, res); } ans += op; ans %= n; cout << ans << '\n'; } } int main() { std::cin.tie(nullptr); std::ios_base::sync_with_stdio(false); int T = 1; for (int t = 0; t < T; t++) { solve(); } return 0; }