#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
const int max_n = 1e6+100;
int q;
ll a[max_n],c[max_n];
int p[max_n][22];
inline int find(int u)
{
	for (int i=20;i>=0;--i)if (a[p[u][i]]>0)u=p[u][i];
	return u;
}
int main()
{
	ios::sync_with_stdio(0);
	cin>>q>>a[0]>>c[0];
	for (int i=1;i<=q;++i)
	{
		int ty;cin>>ty;
		if (ty==1)
		{
			cin>>p[i][0]>>a[i]>>c[i];
			for (int k=1;k<=20;++k)p[i][k]=p[p[i][k-1]][k-1];
		}
		else
		{
			int v,w;
			cin>>v>>w;
			ll ans=0;int res=0;
			while (w)
			{
				int id = find(v);
				if (a[id]==0)break;
				if (a[id]>=w)
				{
					ans+=w*c[id];
					a[id]-=w;
					res+=w;
					break;
				}
				else
				{
					ans+=c[id]*a[id];
					w-=a[id];
					res+=a[id];
					a[id]=0;
				}
			}
			cout<<res<<" "<<ans<<endl;
		}
	}
}