#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long int n, q;
  cin >> n >> q;
  long long int left, right, root, i, j, k;
  map<long long int, long long int> mp;
  while (q--) {
    mp.clear();
    left = 0;
    right = n + 1;
    long long int x;
    cin >> x;
    string s;
    cin >> s;
    root = (left + right) / 2;
    mp[root] = root;
    while (root != x) {
      if (x < root) {
        right = root;
        root = (left + right) / 2;
        mp[root] = right;
      } else if (x > root) {
        left = root;
        root = (left + right) / 2;
        mp[root] = left;
      }
    }
    for (i = 0; i < s.length(); i++) {
      if (s[i] == 'L') {
        if (right - root == 1 || root - left == 1)
          continue;
        else {
          right = root;
          root = (left + right) / 2;
          mp[root] = right;
        }
      } else if (s[i] == 'R') {
        if (right - root == 1 || root - left == 1)
          continue;
        else {
          left = root;
          root = (left + right) / 2;
          mp[root] = left;
        }
      } else {
        if (mp[root] > root) {
          root = mp[root];
          right = right + (right - left);
        } else if (mp[root] < root) {
          root = mp[root];
          left = left - (right - left);
        }
      }
    }
    cout << root << "\n";
  }
  return 0;
}
