#include <bits/stdc++.h>
using namespace std;
pair<long long, long long> tata[100];
int c;
long long n;
void find(long long x);
void operation(char op);
int main() {
  ios_base ::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  int k;
  long long val;
  cin >> k;
  while (k--) {
    cin >> val;
    find(val);
    string s;
    cin >> s;
    for (auto i : s) operation(i);
    cout << (tata[c - 1].first + tata[c - 1].second) / 2 << '\n';
  }
  return 0;
}
void operation(char op) {
  if (op == 'U') {
    if (c == 1) return;
    c--;
    return;
  }
  if (tata[c - 1].first == tata[c - 1].second) return;
  if (op == 'L')
    tata[c] = {tata[c - 1].first,
               (tata[c - 1].first + tata[c - 1].second) / 2 - 1};
  else
    tata[c] = {(tata[c - 1].first + tata[c - 1].second) / 2 + 1,
               tata[c - 1].second};
  c++;
}
void find(long long x) {
  c = 1;
  tata[0] = {1, n};
  long long valtata((tata[c - 1].first + tata[c - 1].second) / 2);
  while (valtata != x) {
    if (x < valtata)
      tata[c] = {tata[c - 1].first, valtata - 1};
    else
      tata[c] = {valtata + 1, tata[c - 1].second};
    c++;
    valtata = (tata[c - 1].first + tata[c - 1].second) / 2;
  }
}
