/*
    Let everything happen to you
    Beauty and Terror
    Just keep going
    No feeling is final
        - Rainer Maria Rilke
*/

#include<bits/stdc++.h>
#define ll long long
#define endl '\n'
#define IOS ios::sync_with_stdio(0); cin.tie(0);
#define fio freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#define pb push_back
#define MOD 1000000007LL
//#define MOD 998244353LL
#define all(x) (x).begin(),(x).end()

using namespace std;

int main()
{
    #ifndef ONLINE_JUDGE
        fio
    #endif
    IOS     

    int n = 1;
    vector<ll> cost(300005, 0), gold(300005, 0);
    
    ll q, g, c, p; cin >> q >> g >> c;

    gold[0] = g;
    cost[0] = c;

    vector<vector<int>> par(300005, vector<int>(20, -1));

    for(int i = 0; i < 20; i++){
        par[0][i] = 0;    
    }

    for(int cs = 1; cs <= q; cs++){
        int t; cin >> t;
        if(t == 1){
            cin >> p >> g >> c;
            
            int cv = cs;

            gold[cv] = g;
            cost[cv] = c;

            for(int i = 0; i < 20; i++){
                if(i == 0) par[cv][i] = p;
                else par[cv][i] = par[par[cv][i - 1]][i - 1];
            }
        }
        else{
            int v, w;
            cin >> v >> w;

            ll resg = 0, resc = 0;

            while(w){
                int root = v;
                for(int i = 19; i >= 0; i--){
                    if(gold[par[root][i]] == 0) continue;
                    else root = par[root][i];
                }

                if(gold[root] >= w){
                    gold[root] -= w;
                    resg += w;
                    resc += w * cost[root];
                    break;
                }
                else{
                    resc += gold[root] * cost[root];
                    resg += gold[root];
                    w -= gold[root];
                    gold[root] = 0;
                }

                if(root == v) break;
            }

            cout << resg << " " << resc << endl;
            cout.flush();
        }
    }

    return 0;
}
