#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e6 + 10;
char op[MAXN];
int node[MAXN], depth[MAXN];
int dp[20][MAXN];
int cnt, cur;
void Init(){
depth[0] = 0;
cnt = cur = 0;
}
void TypeLetter(char l){
cnt ++; cur ++;
op[cur] = l;
node[cnt] = cur;
dp[0][cur] = node[cnt - 1];
depth[cur] = depth[node[cnt - 1]] + 1;
for(int k=1; k<20; k++) dp[k][cur] = dp[k - 1][dp[k - 1][cur]];
}
void UndoCommands(int u){
cnt ++;
node[cnt] = node[cnt - u - 1];
cur = node[cnt];
}
char GetLetter(int p){
int x = cur;
for(int k=19; k>=0; k--){
if(depth[dp[k][x]] > p){
x = dp[k][x];
}
}
return op[x];
}