#include <stdio.h>
#include <string.h>

#define MAXN 1010
#define MAXL 110

int n, m, p[MAXN];
char s[MAXN][MAXL + 1];

static char buf[655360];

int main()
{
  freopen("windows.in", "rt", stdin);
  freopen("windows.out", "wt", stdout);

  gets(buf);
  sscanf(buf, "%d", &n);
  m = 0;
  for (int i=0;i<n;i++)
  {
    gets(buf);
    if (buf[0] == 'R')
    {
      strcpy(s[m++], buf + 4);
      memmove(p + 1, p, (m - 1) * sizeof(int));
      p[0] = m - 1;
    }
    else
    {
      int k = 0;
      for (char *c=buf;*c;c++)
        k += (*c == '+');
      k %= m;
      int t = p[k];
      if (k)
        memmove(p + 1, p, k * sizeof(int));
      p[0] = t;
    }
    puts(s[p[0]]);   
  }

  return 0;
}
