#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const long long MX = 1e17;
const long long SZ = 5e5 + 5;
template <typename T>
T power(T b, T p, T m) {
  if (p == 0) return 1;
  if (p % 2 == 0) {
    T s = power(b, p / 2, m);
    return ((s % m) * (s % m)) % m;
  }
  return ((b % m) * (power(b, p - 1, m) % m)) % m;
}
template <typename T>
T ModInv(T b, T m) {
  return power(b, m - 2, m);
}
bool Check(long long v, long long i) { return (v & (1LL << i)); }
long long Set(long long v, long long i) { return (v | (1LL << i)); }
long long n, m, k;
string s, s1;
long long root, ver, dep;
pair<long long, long long> a[SZ];
long long get_num(long long st, long long en) { return ((st + en) / 2); }
void find_node(long long node, long long st, long long p) {
  a[++dep] = {node, st};
  if (node == ver) return;
  if (ver < node)
    find_node(get_num(st, node - 1), st, node);
  else
    find_node(get_num(node + 1, node * 2 - st), node + 1, node);
}
long long go(long long ps, long long node, long long st, bool down) {
  if (ps >= (long long)s.size()) return node;
  if (down) a[++dep] = {node, st};
  if (s[ps] == 'U' && node == root) return go(ps + 1, node, st, 0);
  if ((s[ps] == 'L' || s[ps] == 'R') && st == node)
    return go(ps + 1, node, st, 0);
  if (s[ps] == 'U') {
    dep--;
    return go(ps + 1, a[dep].first, a[dep].second, 0);
  }
  if (s[ps] == 'L')
    return go(ps + 1, get_num(st, node - 1), st, 1);
  else
    return go(ps + 1, get_num(node + 1, node * 2 - st), node + 1, 1);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long i, j, x, y, z, ans = 0, cnt = 0, t = 0;
  long long q, testcase = 1;
  cin >> n >> q;
  root = (1 + n) / 2;
  while (q--) {
    cin >> ver >> s;
    dep = 0;
    find_node(root, 1, 0);
    cout << go(0, ver, a[dep].second, 0) << "\n";
  }
  return 0;
}
