#include<bits/stdc++.h>
#define int long long
using namespace std;
int q,d[35][300005],a[300005],c[300005];
inline int read(){
	long long w=0,x=1;
	char c=getchar();
	while(c>'9'||c<'0'){
		if(c=='-')x=-1;
	}
	while(c<='9'&&c>='0'){
		w=(w<<1)+(w<<3)+(c^48);
		c=getchar();
	}
	return w*x;
}
pair<int,int> ask(int v,int w){
    int s=0,t=0;
    while(w>0){
        int u=v;
        for(int i=30;i>=0;--i)if(a[d[i][u]]>0)u=d[i][u];
        int x=min(w,a[u]);a[u]-=x,w-=x,s+=x,t+=c[u]*x;
        if(u==v)break;
    }return make_pair(s,t);
}
signed main(){
	cin>>q>>a[0]>>c[0];
    for(int i=1;i<=q;++i){
        int op,u,v,w;cin>>op>>u>>v;
        if(op==1){cin>>w;d[0][i]=u;a[i]=v;c[i]=w;for(int j=1;j<=30;++j)d[j][i]=d[j-1][d[j-1][i]];
        }else{pair<int,int>s=ask(u,v);cout<<s.first<<" "<<s.second<<endl;}
    }
}