#include <bits/stdc++.h>
using namespace std;
struct node {
  long long value;
  long long l, r;
  node* left;
  node* right;
  node* parent;
  node() {
    left = right = parent = 0;
    value = 0;
  }
  void extend(bool flag) {
    if (flag) {
      left = new node;
      left->parent = this;
      left->value = (l + value - 1) / 2;
      left->l = l;
      left->r = value - 1;
    } else {
      right = new node;
      right->parent = this;
      right->value = (value + 1 + r) / 2;
      right->l = value + 1;
      right->r = r;
    }
  }
};
node* get(node* root, long long value) {
  if (root->value == value) return root;
  if (value < root->value) {
    if (root->left == 0) root->extend(true);
    return get(root->left, value);
  } else {
    if (root->right == 0) root->extend(false);
    return get(root->right, value);
  }
}
node* go(node* root, char dir) {
  if (dir == 'U') {
    if (root->parent) return root->parent;
    return root;
  } else if (dir == 'L') {
    if (root->left)
      return root->left;
    else if (!(root->value % 2)) {
      root->extend(true);
      return root->left;
    }
    return root;
  } else {
    if (root->right)
      return root->right;
    else if (!(root->value % 2)) {
      root->extend(false);
      return root->right;
    }
    return root;
  }
}
void clean(node* root) {
  if (root->left) clean(root->left);
  if (root->right) clean(root->right);
  delete root;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  long long n;
  int q;
  cin >> n >> q;
  node* root;
  node* temp;
  for (int i = 0; i < q; i++) {
    root = new node;
    root->value = (1 + n) / 2;
    root->l = 1;
    root->r = n;
    long long value;
    cin >> value;
    temp = get(root, value);
    string str;
    cin >> str;
    for (decltype((str).begin()) it = (str).begin(); it != (str).end(); it++)
      temp = go(temp, *it);
    cout << temp->value << "\n";
    clean(root);
  }
  return 0;
}
