#include <bits/stdc++.h>
using namespace std;
long long t[26] = {};
struct N
{
string l;
int r {};
vector<N> v;
};
string PS;
void read(N& n, int B)
{
istringstream g;
if(n.r) g = istringstream(n.l);
#define I(X)string X;if(n.r) g >> X; else while(true) {if((cin >> ws).eof()) return; cin >> X; auto p = X.find("#"); if(p != string::npos) {X = X.substr(0, p); if(cin.peek() != '\n') cin.ignore(1000, '\n');if(!X.size()) continue;} n.l += " "; n.l += X; cin.get(); break;}
size_t i {};
while(true)
{
I(f);
if(f == ")")
{
n.r = 1;
return;
}
if(f == "PRINT")
{
I(x);
if(!B) cout << t[x[0] - 'A'] << " " << flush;
}
else if(f == "INCREASE")
{
I(x);
if(!B) ++t[x[0] - 'A'];
}
else if(f == "CLEAR")
{
I(x);
if(!B) t[x[0] - 'A'] = 0;
}
if(f == "REPEAT")
{
I(x);
I(ti);
I(st);
if(n.v.size() == i) n.v.resize(i + 1);
if(t[x[0] - 'A'] == 0 || B)
read(n.v[i], 1);
else for(long long k = t[x[0] - 'A']; k != 0; --k)
read(n.v[i], 0);
++i;
}
}
}
int main()
{
cin.tie(nullptr);
cin.sync_with_stdio(false);
N n;
read(n, 0);
cout << flush;
return 0;
}