#include<cstdio>
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
struct kd{
int k,bz,tp[101];
long long sz,lst[101][2];
string nms[101];
};
struct ad{
int l;
string S[100];
};
int n,op,l=5,flag,k;
long long addr;
kd kds[105];
string names[105],tp,nm;
ad AD;
int fd(string name){
for(int i=0;i<l;i++){
if(names[i]name){
return i;
}
}
return -1;
}
long long f(long long a,int b){
return(a+b-1)/b*b;
}
void add(int id_1,string nm,int id_2){
kds[id_1].k++;
kds[id_1].tp[kds[id_1].k]=id_2;
kds[id_1].nms[kds[id_1].k]=nm;
kds[id_1].lst[kds[id_1].k][0]=f(kds[id_1].lst[kds[id_1].k-1][1],kds[id_2].bz);
kds[id_1].lst[kds[id_1].k][1]=kds[id_1].lst[kds[id_1].k][0]+kds[id_2].sz;
kds[id_1].bz=max(kds[id_1].bz,kds[id_2].bz);
kds[id_1].sz=f(kds[id_1].lst[kds[id_1].k][1],kds[id_1].bz);
return;
}
void init_basic(int ind,string name,long long sz,int bz){
kds[ind].bz=bz;
kds[ind].sz=sz;
names[ind]=name;
return;
}
void init(){
init_basic(1,"byte",1,1);
init_basic(2,"short",2,2);
init_basic(3,"int",4,4);
init_basic(4,"long",8,8);
return;
}
ad ipt(){
char c=getchar();
ad ans;ans.l=0;
while(c<'a'||c>'z'){
c=getchar();
}
while((c>='a'&&c<='z')||c'.'){
if(c=='.'){
ans.l++;
}else{
ans.S[ans.l]+=c;
}
c=getchar();
}
ans.l++;
return ans;
}
void opt(ad a){
for(int i=0;i<a.l-1;i++){
cout<<a.S[i]<<".";
}
cout<<a.S[a.l-1]<<endl;
return;
}
long long solve1(int now,int ind){
if(indAD.l){
return 0;
}
for(int i=1;i<=kds[now].k;i++){
if(kds[now].nms[i]AD.S[ind]){
return kds[now].lst[i][0]+solve1(kds[now].tp[i],ind+1);
}
}
return-1;
}
void solve2(int now,long long addr){
if(addr>=kds[now].sz){
flag=1;
return;
}
if(kds[now].k0){
return;
}
for(int i=1;i<=kds[now].k;i++){
if(kds[now].lst[i][0]<=addr&&kds[now].lst[i][1]>addr){
AD.S[AD.l++]=kds[now].nms[i];
solve2(kds[now].tp[i],addr-kds[now].lst[i][0]);
return;
}
}
flag=1;
return;
}
int main(){
freopen("struct.in","r",stdin);
freopen("struct.out","w",stdout);
scanf("%d",&n);
init();
for(int i=0;i<n;i++){
scanf("%d",&op);
if(op1){
cin>>names[l];
scanf("%d",&k);
for(int j=0;j<k;j++){
cin>>tp>>nm;
add(l,nm,fd(tp));
}
printf("%lld %d\n",kds[l].sz,kds[l].bz);l++;
}else if(op2){
cin>>tp>>nm;
add(0,nm,fd(tp));
printf("%lld\n",kds[0].lst[kds[0].k][0]);
}else if(op3){
AD=ipt();
printf("%lld\n",solve1(0,0));
}else{
scanf("%lld",&addr);
AD.l=0;
flag=0;
solve2(0,addr);
if(flag){
printf("ERR\n");
}else{
opt(AD);
}
}
}
fclose(stdin);
fclose(stdout);
return 0;
}