#include<bits/stdc++.h>
#define int long long
using namespace std;
inline int read()
{
int s=0,w=1;
char ch=getchar();
while(ch<'0'||ch>'9')
{
if(ch=='-')w=-1;
ch=getchar();
}
while(ch>='0'&&ch<='9')
{
s=(s<<3)+(s<<1)+(ch^48);
ch=getchar();
}
return s*w;
}
inline void print(int x)
{
if(x<0)
{
putchar('-');
x=-x;
}
if(x>=10)print(x/10);
putchar(x%10+48);
}
int wei=0,T,op;
map<string,int> mp;
map<string,int> dx;
struct edge
{
string first,second;
int st;
};
map<string,vector<edge> > ys;
string s,ti,ni,t,n,st[15];
int sum;
int k,tot;
map<string,int> id,ID;
map<string,string> pp;
inline void work(int dep,string nd)
{
if(dep==tot+1)return;
int len=0;
string to="";
cout<<dep<<' '<<nd<<"\n";
if(dep==1)
{
len=id[st[dep]];
}
else
{
for(int i=0;i<(int)ys[nd].size();i++)
{
auto now=ys[st[dep-1]][i];
if(now.second==st[dep])
{
to=now.first;
len=now.st;
}
}
}
work(dep+1,to);
sum+=len;
}
inline __int128 gcd(__int128 a,__int128 b)
{
return !b?a:gcd(b,a%b);
}
inline __int128 lcm(__int128 a,__int128 b)
{
return a*b/gcd(a,b);
}
signed main()
{
T=read();
mp["byte"]=dx["byte"]=1;
mp["short"]=dx["short"]=2;
mp["int"]=dx["int"]=4;
mp["long"]=dx["long"]=8;
for(int _=1;_<=T;_++)
{
op=read();
if(op==1)
{
cin>>s;
k=read();
int duiqi=1,daxiao=0;
int kk=0;
for(int i=1;i<=k;i++)
{
cin>>ti>>ni;
int tt=(daxiao+mp[ti]-1)/mp[ti]*mp[ti];
ys[s].push_back({ti,ni,tt});
kk=tt;
daxiao=kk+dx[ti];
if(k==1)duiqi=mp[ti];
else duiqi=lcm(duiqi,mp[ti]);
}
int tt=(daxiao+duiqi-1)/duiqi*duiqi;
daxiao=tt;
print(daxiao);
putchar(' ');
print(duiqi);
puts("");
mp[s]=duiqi;
dx[s]=daxiao;
}
if(op==2)
{
cin>>t>>n;
int duiqi=mp[t];
int tt=(wei+duiqi-1)/duiqi*duiqi;
int l=tt,r=tt+dx[t]-1;
id[n]=l;
ID[n]=r;
wei=r+1;
print(l);
pp[n]=t;
puts("");
}
}
return 0;
}