#include <iostream>
#include <string>
#define MAXN 2000
using namespace std;
struct node
{
char c;
int place;
};
node _node[MAXN];
int index;
void fun_q(int place);
int len;
string s;
int main()
{
//freopen("acm.acm","r",stdin);
int op;
char c;
char c_1;
int q_place;
int i_place;
cin>>s;
cin>>op;
len = s.length();
index = 0;
while(op --)
{
cin>>c;
if(c == 'Q')
{
cin>>q_place;
fun_q(q_place);
}
else if(c == 'I')
{
cin>>c_1;
cin>>i_place;
if(i_place > len)
{
_node[index].c = c_1;
_node[index].place = len+1;
++ index;
++ len;
}
else
{
++ len;
_node[index].c = c_1;
_node[index].place = i_place;
++ index;
}
}
}
}
void fun_q(int place)
{
int i;
int p = place;
for(i = index-1; i >= 0; -- i)
{
// cout<<p<<"))))))))))))) "<<endl;
if(_node[i].place < p)
{
-- p;
}
else if(_node[i].place == p)
{
cout<<_node[i].c<<endl;
return;
}
}
cout<<s[p-1]<<endl;
}