#include<bits/stdc++.h>
#define fastIO   ios_base::sync_with_stdio(false); cin.tie(NULL);
#define int      long long 
#define all(v)   (v).begin(), (v).end()
using namespace std;

const int mod = 1e9+7;
int add(int a,int b){return (a%mod+b%mod)%mod;}
int mult(int a,int b){return (a%mod*b%mod)%mod;}
int sub(int a,int b){return (a%mod-b%mod+mod)%mod;}

int q;
vector<int> a,c;
vector< vector<int> > parent;

int findMy(int v) {
    if(a[v] == 0) return -1;
    for(int i=24; i>=0; i--)
        if(a[parent[v][i]] != 0)
            v = parent[v][i];
    return v;
}

pair<int,int> helper(int v, int w) {
    int taken = 0, amt = 0;
    while(1){
        int topMost = findMy(v);
        if(topMost == -1 || w == 0) break;
        int taking = min(w, a[topMost]);
        w -= taking;
        taken += taking;
        a[topMost] -= taking;
        amt += taking*c[topMost];
    }
    return {taken, amt};
} 

void solve()
{	
	cin>>q;
    a.assign(q+1,0);
    c.assign(q+1,0);
    cin>>a[0]>>c[0];
    parent.assign(q+1, vector<int>(25));

    for(int i=0; i<25; i++) parent[0][i] = 0;

    for(int k=1; k<=q; k++){
        int type;
        cin>>type;
        if(type == 1) {
            cin>>parent[k][0]>>a[k]>>c[k];
            for(int i=1; i<25; i++)
                parent[k][i] = parent[parent[k][i-1]][i-1];
        } else {
            int v, w;
            cin>>v>>w;
            //from path 0 to v we have to get w tons of gold at cheapest price
            //find the first node in path at which a value is non zero
            pair<int,int> p = helper(v,w);
            cout<<p.first<<" "<<p.second<<endl;
        }
    }
}

int32_t main()
{
	fastIO;
	int tc=1;
	//cin>>tc;
	for(int i=1; i<=tc; i++)
	{
		//cout<<"Case #"<<i<<": ";
		solve();
	}	
}