#include <bits/stdc++.h>
long long n, cur;
int q;
char s[111111];
long long lowbit(long long x) { return x & -x; }
int main() {
  scanf("%I64d%d", &n, &q);
  for (int i = 0; i < q; i++) {
    scanf("%I64d%s", &cur, s);
    int len = strlen(s);
    for (int j = 0; j < len; j++) {
      if (s[j] == 'L')
        cur -= lowbit(cur) / 2;
      else if (s[j] == 'R')
        cur += lowbit(cur) / 2;
      else if (cur != (n + 1) / 2) {
        if (cur & (lowbit(cur) << 1))
          cur -= lowbit(cur);
        else
          cur += lowbit(cur);
      }
    }
    printf("%I64d\n", cur);
  }
  return 0;
}
