#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 10;
long long n;
char s[MAXN];
inline pair<long long, pair<long long, long long> > find(long long x) {
  long long rt = ((n + 1) >> 1), delta = ((n + 1) >> 2);
  long long fa = -1, ls = -1, rs = -1;
  while (rt != x) {
    fa = rt;
    if (rt < x)
      rt += delta;
    else
      rt -= delta;
    delta >>= 1;
  }
  if (delta) ls = rt - delta, rs = rt + delta;
  return make_pair(fa, make_pair(ls, rs));
}
inline void L(long long &x) {
  pair<long long, pair<long long, long long> > tmp = find(x);
  if (tmp.second.first != -1) x = tmp.second.first;
}
inline void R(long long &x) {
  pair<long long, pair<long long, long long> > tmp = find(x);
  if (tmp.second.second != -1) x = tmp.second.second;
}
inline void U(long long &x) {
  pair<long long, pair<long long, long long> > tmp = find(x);
  if (tmp.first != -1) x = tmp.first;
}
void solve() {
  long long cur;
  scanf("%lld\n%s", &cur, s + 1);
  int len = strlen(s + 1);
  for (int i = 1; i <= len; i++) {
    if (s[i] == 'L')
      L(cur);
    else if (s[i] == 'R')
      R(cur);
    else
      U(cur);
  }
  printf("%lld\n", cur);
}
int main() {
  int T;
  scanf("%lld%d", &n, &T);
  while (T--) solve();
  return 0;
}
