#include<bits/stdc++.h>
#define int long long
using namespace std;
#define pb push_back
#define rep(i,a,b) for(int i=a;i<=b;++i)
#define per(i,a,b) for(int i=a;i>=b;--i)
#define s(v) (int)v.size()
const int mod = 998244353, N = 2e5+5, M = 1e5+5, INF = 1e9;
struct node {
string name;
int dq,len;
vector<pair<int,int>> vc;
vector<string> elename;
node() { name="",dq=len=0,vc.clear(),elename.clear(); };
node(string nm,int d,int l)
{ name=nm,dq=d,len=l,vc.clear(),elename.clear(); };
node(string nm,int d,int l,pair<int,int> p,string s)
{ name=nm,dq=d,len=l,vc.clear(),elename.clear();vc.pb(p),elename.pb(s); };
};
node types[103]; int tot;
map<string,int> mp;
int nowpos=0;
inline int sgm(int a,int b) { return b*((a+b-1)/b); }
void build() {
string name;
int n,now=0;
cin>>name>>n;
mp[name]=tot;
types[tot]=node(name,0,0);
string t,e;
rep(i,1,n) {
cin>>t>>e;
int id=mp[t];
types[tot].dq=max(types[tot].dq,types[id].dq);
types[tot].vc.pb({id,sgm(now,types[id].dq)});
now=sgm(now,types[id].dq)+types[id].len;
types[tot].elename.pb(e);
}
types[tot].len=sgm(now,types[tot].dq);
cout<<types[tot].len<<' '<<types[tot].dq<<'\n';
tot++;
}
struct element {
int stpos,type;
string name;
element() {stpos=type=0,name="";};
element(int s,int t,string n) {stpos=s,type=t,name=n;};
};
vector<element> mem;
void makenew() {
string type,name;
cin>>type>>name;
int tp=mp[type];
element nw=element(sgm(nowpos,types[tp].dq),tp,name);
mem.pb(nw);
nowpos=nw.stpos+types[tp].len;
cout<<nw.stpos<<'\n';
}
void visele() {
string s,zc="";
cin>>s; s=s+".";
vector<string> v;
for(auto c:s) {
if(c=='.') v.pb(zc),zc="";
else zc=zc+c;
}
int pos=0,tp=0;
for(auto c:mem)
if(c.name==v[0])
pos=c.stpos,tp=c.type;
rep(i,1,s(v)-1) {
rep(j,0,s(types[tp].elename)-1) {
if(types[tp].elename[j]==v[i]) {
pos=sgm(pos,types[types[tp].vc[j].first].dq),
tp=types[tp].vc[j].first;
break;
} else
pos=sgm(pos,types[types[tp].vc[j].first].dq)+types[types[tp].vc[j].first].len;
}
} cout<<pos<<'\n';
}
void visadd() {
int ad,tp=-1,pos=0; cin>>ad;
string res="";
for(auto c:mem)
if(c.stpos<=ad&&c.stpos+types[c.type].len>ad)
tp=c.type,pos=c.stpos,res=c.name;
if(tp==-1) { cout<<"ERR\n"; return; }
while(true) {
vector<string> elenm=types[tp].elename;
if(s(elenm)<=0) break;
vector<pair<int,int> > vc=types[tp].vc;
tp=-1;
rep(i,0,s(elenm)-1) {
int st=sgm(pos,types[vc[i].first].dq),len=types[vc[i].first].len;
if(st<=ad&&ad<st+len) {
tp=vc[i].first,
res=res+"."+elenm[i];
break;
} else pos=st+len;
}
if(tp==-1) { cout<<"ERR\n"; return; }
} cout<<res<<'\n';
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr),cout.tie(nullptr);
types[tot++]=node("byte",1,1),mp["byte"]=0;
types[tot++]=node("short",2,2),mp["short"]=1;
types[tot++]=node("int",4,4),mp["int"]=2;
types[tot++]=node("long",8,8),mp["long"]=3;
int n; cin>>n;
while(n--) {
int opr; cin>>opr;
if(opr==1) build();
else if(opr==2) makenew();
else (opr==3)?visele():visadd();
}
return 0;
}
rt。