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

int q, sp[20][300300], a[300300], c[300300];

int find_lowest(int u){
    if(!a[u]) return -1;

    int x = u, re = 0;
    for(int i=19;i>=0;i--) if(a[sp[i][x]]) x = sp[i][x], re += (1 << i);
    return re;
}

int up(int u, int k){
    for(int i=0;i<20;i++) if((1 << i) & k) u = sp[i][u];
    return u;
}

int main(){
    cin.tie(0)->sync_with_stdio(0);
    cin >> q >> a[1] >> c[1];

    for(int i=2;i<=q+1;i++){
        int t; cin >> t;
        if(t == 1){
            cin >> sp[0][i] >> a[i] >> c[i]; sp[0][i]++;
            for(int j=1;j<20;j++) sp[j][i] = sp[j-1][sp[j-1][i]];

        }else{
            int v, w; cin >> v >> w; v++;

            int k = find_lowest(v);

            ll cnt = 0, sum = 0;

            while(k >= 0 && w){
                int u = up(v, k);

                int pl = min(w, a[u]);
                cnt += pl, w -= pl, a[u] -= pl, sum += 1ll * pl * c[u];

                k--;
            }

            cout << cnt << " " << sum << "\n";
            cout.flush();
        }
    }
}