#include #include using namespace std; using namespace atcoder; using ll = long long; using ull = unsigned long long; template inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } const vector dx = {0,0,1,-1}; const vector dy = {1,-1,0,0}; const ll INF = 1e18; const ll MOD = 998244353; int main(){ int n,q; cin >> n >> q; string s; cin >> s; for(int i = 0; i < q; i++){ int h,w,p; cin >> h >> w >> p; int x = 0, y = 0; while(x != h && y != w){ if(x == h){ break; }else if(y == w){ break; }else{ if(s[p] == 'D'){ x++; p = (p+1)%n; }else{ y++; p = (p+1)%n; } } } cout << p << endl; } }