#include <bits/stdc++.h>
using namespace std;
long long int bit(long long int n) {
  long long int a = 1;
  while (n % 2 == 0) {
    n /= 2;
    a *= 2;
  }
  return a;
}
long long int n, x;
int q;
string s;
int main() {
  cin >> n;
  cin >> q;
  n = (n + 1) / 2;
  for (int k = 0; k < q; k++) {
    cin >> x;
    cin >> s;
    for (int a = 0; a < s.size(); a++)
      if (n % 2 == 0) {
        if (s[a] == 'U' && bit(x) * 2 <= n) {
          if ((x - bit(x)) / (bit(x) * 2) % 2 == 0)
            x += bit(x);
          else
            x -= bit(x);
        } else if (s[a] == 'R')
          x += bit(x) / 2;
        else if (s[a] == 'L')
          x -= bit(x) / 2;
      }
    cout << x << endl;
  }
}
