#include<iostream>
#include<cstdio>
#include<vector>
#include<map>
#include<cstring>
using namespace std;
int n;
struct e {
string ty, a;
int begin, end;
};
struct node {
int almax, len;
vector<e>v;
};
map<string, int> bsty;
map<string, node>ty;
vector<e>C_nint;
void op1() {
string s;
int k, ans = 0;
cin >> s >> k;
vector<string> g;
vector<string>tye;
for(int i = 1; i <= k; i++) {
string t, num;
cin >> t >> num;
if(bsty.find(t) != bsty.end()) {
ans = max(ans, bsty[t]);
} else {
ans = max(ans, ty[t].almax);
}
g.push_back(num);
tye.push_back(t);
}
vector<e>pp;
int cnt = -1;
for(int i = 0; i < k; i++) {
string t = tye[i], a = g[i];
int begin = cnt + 1;
if(bsty.find(t) != bsty.end()) {
cnt += ans;
} else {
cnt += ty[t].len;
}
pp.push_back({t, a, begin, cnt});
}
ty[s] = {ans, cnt + 1, pp};
cout << cnt + 1 << ' ' << ans << '\n';
return ;
}
int C_nt = -1;
void op2() {
string t, a;
cin >> t >> a;
cout << C_nt + 1 << '\n';
int begin = C_nt + 1;
if(bsty.find(t) != bsty.end()) {
C_nt += bsty[t];
} else {
C_nt += ty[t].len;
}
C_nint.push_back({t, a, begin, C_nt});
}
void op3() {
string s;
cin >> s;
int it = 0;
string str = "";
int len = s.size();
int beg;
while(s[it] != '.') {
str += s[it];
it++;
}
for(int i = 0; i < C_nint.size(); i++) {
if(str == C_nint[i].a) {
beg = C_nint[i].begin;
str = C_nint[i].ty;
break;
}
}
string fstr = "";
while(it < len) {
fstr = "";
while(s[it] != '.' && it < len) {
fstr += s[it];
it++;
}
for(int i = 0; i < ty[str].v.size(); i++) {
if(fstr == ty[str].v[i].a) {
beg +=ty[str].v[i].begin;
str = ty[str].v[i].ty;
break;
}
}
it++;
}
cout <<beg << '\n';
return ;
}
void op4() {
int addr;
cin >> addr;
string str, a;
int beg;
for(int i = 0; i < C_nint.size(); i++) {
if(addr <= C_nint[i].end) {
beg = C_nint[i].begin;
str = C_nint[i].ty;
a = C_nint[i].a;
break;
}
}
if(bsty.find(str) != bsty.end()) {
cout << a << '\n';
return ;
}
cout << a;
while(1) {
for(int i = 0; i < ty[str].v.size(); i++) {
int begin = beg + ty[str].v[i].begin, end = beg + ty[str].v[i].end;
if(begin <= addr && end >= addr) {
beg = begin;
a = ty[str].v[i].a;
str = ty[str].v[i].ty;
break;
}
}
cout << ".";
if(bsty.find(str) != bsty.end()) {
cout << a << '\n';
return ;
}
cout << a;
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n;
bsty["byte"] = 1;
bsty["short"] = 2;
bsty["int"] = 4;
bsty["long"] = 8;
for(int i = 1; i <= n; i++) {
int opt;
cin >> opt;
if(opt == 1) {
op1();
}
if(opt == 2) {
op2();
}
if(opt == 3) {
op3();
}
if(opt == 4) {
op4();
}
}
return 0;
}