#include <bits/stdc++.h>
using namespace std;
using std::cin;
using std::cout;
long long MOD = 998244353;
int main() {
  long long n, q;
  cin >> n >> q;
  for (int i = 0; i < q; i++) {
    long long curr;
    cin >> curr;
    string s;
    cin >> s;
    for (int c = 0; c < s.size(); c++) {
      long long bit = curr & -curr;
      if (s[c] == 'U') {
        if (curr != (n + 1) / 2) {
          if (((curr - bit) & -(curr - bit)) != bit * 2)
            curr += bit;
          else
            curr -= bit;
        }
      } else if (s[c] == 'R') {
        if (bit == 1)
          curr += 0;
        else
          curr += bit / 2;
      } else if (s[c] == 'L') {
        if (bit == 1)
          curr += 0;
        else
          curr -= bit / 2;
      }
    }
    cout << curr << "\n";
  }
  return 0;
}
