#include <bits/stdc++.h>
using namespace std;
struct state {
  long long k;
  long long add;
  long long get() const { return k + add; }
};
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long N;
  int q;
  cin >> N >> q;
  while (q--) {
    long long x;
    cin >> x;
    vector<state> prev;
    state curr = {(N + 1) / 2, 0};
    while (curr.get() != x) {
      if (x < curr.get()) {
        prev.push_back(curr);
        curr.k /= 2;
      } else {
        prev.push_back(curr);
        curr.add += curr.k;
        curr.k /= 2;
      }
    }
    string s;
    cin >> s;
    for (int i = 0; i < (int)(s).size(); ++i) {
      if (s[i] == 'U') {
        if (prev.empty()) {
          continue;
        } else {
          curr = prev.back();
          prev.pop_back();
        }
        continue;
      }
      if (curr.get() & 1) {
        continue;
      }
      if (s[i] == 'L') {
        prev.push_back(curr);
        curr.k /= 2;
      } else {
        prev.push_back(curr);
        curr.add += curr.k;
        curr.k /= 2;
      }
    }
    cout << curr.get() << "\n";
  }
}
