#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define pii pair<int,int>
const ll lp = 1e9+7;
const int msize = 3e5+7;
const int mlog = 32;

int m,n,k,cnt,qcnt,idx,len,temp,test_cnt;
ll amount[msize], cost[msize];
int sparseanc[msize][32]; //*pii for node,amount, if amount of that ancestor is different, it means the gold for all above nodes are consumed

int spfind(int idx, int step){
    for (int i=step; i>=0; --i){
        int anc = sparseanc[idx][i];
        if (anc != -1 && amount[anc] > 0){
            return spfind(anc,--step);
        }
    }
    return idx;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    for (int i=0; i<msize; ++i){
        amount[i] = 0;
        cost[i] = 0;
        for (int j=0; j<32; ++j){
            sparseanc[i][j] = -1;
        }
    }

    cin >> qcnt >> amount[0] >> cost[0];

    int type,tnode;
    for (int i=1; i<=qcnt; ++i){
        cin >> type;
        if (type == 1){
            cin >> sparseanc[i][0] >> amount[i] >> cost[i];

            int ancnum=0;
            while(sparseanc[i][ancnum] != 0){
                sparseanc[i][ancnum+1] = sparseanc[sparseanc[i][ancnum]][ancnum];
                //!debug
                //cout << sparseanc[i][ancnum+1] << ":(" << endl;

                ancnum++;
            }
        }else if (type == 2){
            int v,w,top,bought=0;
            ll ans=0;

            cin >> v >> w;
            while(bought < w){
                top = spfind(v,mlog-1);

                //!debug
                //cout << "top is" << " ";
                //cout << top << '\n';

                if (amount[top] == 0) break;

                if (amount[top] >= w-bought){
                    ans += (w-bought)*cost[top];
                    amount[top] -= (w-bought);
                    bought = w;
                }else{
                    ans += amount[top]*cost[top];
                    bought += amount[top];
                    amount[top] = 0;
                }
            }

            cout << bought << " " << ans << endl;
        }
    }
    return 0;
}