#14~20 TLE (换成unordered_map又MLE)
//基本类型和结构体类型都是type
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N=110;
int n,m;
LL id;
map<LL,string> uIdx;//地址到元素的映射
map<string,int> S;//类型映射
map<string,pair<string,LL>> Idx;//元素到(类型,地址)的映射
vector<pair<string,string>> Struct[N];//结构体中定义的元素
pair<int,int> size_type[N];//类型的(长度,对齐要求)
LL idx;
LL duiqi(LL x,string type){//拼音qwq
int size=size_type[S[type]].second;
return (x+size-1)/size*size;
}
int main(){
// freopen("P9754_4.in","r",stdin);
// freopen("P9754_4.out","w",stdout);
cin>>n;
string dtype[4]={"byte","short","int","long"};
for(int i=0;i<4;i++){
S[dtype[i]]=++m;
size_type[m]={1<<i,1<<i};
}
while(n--){
int op;
cin>>op;
if(op==1){
string str;
int k;
cin>>str>>k;
S[str]=++m;
int maxn=0,k1=k,idx1=0;
while(k1--){
string type;
cin>>type>>str;
Struct[m].push_back({type,str});
idx1=duiqi(idx1,type);
idx1+=size_type[S[type]].first;
maxn=max(maxn,size_type[S[type]].second);
}
size_type[m]={(idx1+maxn-1)/maxn*maxn,maxn};
cout<<(idx1+maxn-1)/maxn*maxn<<" "<<maxn;
}
else if(op==2){
string type,str;
cin>>type>>str;
idx=duiqi(idx,type);
cout<<idx;
Idx[str]={type,idx};
for(int i=0;i<size_type[S[type]].first;i++) uIdx[idx+i]=str;
idx+=size_type[S[type]].first;
}
else if(op==3){
string str,tool;//tool是元素名
LL idx1;
cin>>str;
str+='.';
for(int i=0;i<str.length();i++){
if(str[i]=='.'){
idx1=Idx[tool].second;
break;
}
tool+=str[i];
}
string type=Idx[tool].first;//找第一个元素的类型
int len=tool.length()+1;
tool.clear();
for(int i=len;i<str.length();i++){
if(str[i]=='.'){
if(S[type]<=4){
idx1=duiqi(idx1,type);
break;
}
for(auto t:Struct[S[type]]){//遍历上一个结构体类型的元素中的元素
idx1=duiqi(idx1,t.first);
if(t.second==tool){//找到了
type=t.first;
break;
}
idx1+=size_type[S[t.first]].first;
}
tool.clear();
}
else tool+=str[i];
}
cout<<idx1;
}
else{
cin>>id;
if(uIdx.count(id)){
string str=uIdx[id];
LL idx1=Idx[str].second;
string type=Idx[str].first;
bool flag=0;
while(1){
if(S[type]<=4){//若在基本类型的元素里就输出答案
cout<<str;
break;
}
for(auto t:Struct[S[type]]){
idx1=duiqi(idx1,t.first);//每个元素的起始地址
string str1=str+'.'+t.second;
if(id>=idx1&&id<idx1+size_type[S[t.first]].first){//在该元素范围内
type=t.first;
str=str1;
break;
}
if(id<idx1){//起始地址已经超过id且id没被找到
cout<<"ERR";
flag=1;
break;
}
idx1+=size_type[S[t.first]].first;
}
if(flag) break;
}
}
else cout<<"ERR";
}
cout<<endl;
}
return 0;
}