#include <bits/stdc++.h>
using namespace std;
class CompleteBT {
  long long n, q, u;
  map<long long, long long> ancestor;

 public:
  void bs(long long u1, long long n1, long long d) {
    long long next_d;
    if (u1 == n1) return;
    if (u1 > n1)
      next_d = n1 + d / 2;
    else
      next_d = n1 - d / 2;
    ancestor[next_d] = n1;
    bs(u1, next_d, d / 2);
  }
  void read() {
    cin >> n >> q;
    n++;
    string s;
    long long u, fu;
    while (q--) {
      ancestor.clear();
      ancestor[n / 2] = 0;
      cin >> u >> s;
      bs(u, n / 2, n / 2);
      fu = ancestor[u];
      for (long long i = 0; i < s.size(); ++i) {
        if (s[i] == 'U') {
          if (u != n / 2) {
            u = ancestor[u];
            fu = ancestor[u];
          }
        } else if (u % 2 == 0) {
          if (s[i] == 'R') {
            long long dt = abs(fu - u) / 2;
            fu = u;
            u += dt;
            ancestor[u] = fu;
          } else {
            long long dt = abs(fu - u) / 2;
            fu = u;
            u -= dt;
            ancestor[u] = fu;
          }
        }
      }
      cout << u << endl;
    }
  }
};
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  CompleteBT c;
  c.read();
  return 0;
}
