#include<bits/stdc++.h>
using namespace std;
#define int long long
int q;
const int N=3e5+10;
int a[N],c[N],fa[N][20];
signed main(){
    ios::sync_with_stdio(false),cin.tie(0);
    cin>>q>>a[1]>>c[1];
    for(int i=2;i<=q+1;i++){
        int opt,x,v;
        cin>>opt;
        if(opt==1){
            cin>>fa[i][0]>>a[i]>>c[i];
            fa[i][0]++;
            for(int j=1;j<=19;j++) fa[i][j]=fa[fa[i][j-1]][j-1];
        }
        else{
            cin>>x>>v;x++;
            int X=x;
            int sa,sv;sa=sv=0;
            while(v){
                x=X;
                bool ok=0;
                for(int j=19;j>=0;j--){
                    if(fa[x][j]&&a[fa[x][j]]){
                        x=fa[x][j];ok=1;
                    }
                }
                if(a[x]) ok=1;
                if(ok==0) break;
                int val=min(a[x],v);
                sv+=val*c[x];
                sa+=val;
                a[x]-=val;
                v-=val;
                //cout<<">> "<<sa<<"  "<<v<<endl;
            }
            cout<<sa<<" "<<sv<<endl;
        }
    }
}