#include <bits/stdc++.h>
#define ll long long
#define loop(i, a, b) for(ll i=a;i<b;++i)
#define pool(i, a, b) for(ll i=a-1;i>=b;--i)
#define fore(i, a) for(auto&& i:a)
#define fi first
#define se second
#define ps(a) push_back(a)
#define pb(a) pop_back(a)
#define eb(...) emplace_back(__VA_ARGS__)
#define sc scanf
#define vc vector
#define lb lower_bound
#define ub upper_bound
#define all(a) a.begin(), a.end()
#define llmax LLONG_MAX/2
#define llmin -LLONG_MAX/2
using namespace std;
#define mn 500100
#define par pair<ll, ll>
#define ld long double
#define mod 1000000007

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll q;cin >> q;
    ll hei=20;
    
    vc<ll> a(q+1), c(q+1); cin >> a[0] >> c[0];
    vc<vc<ll>> psa(q+1, vc<ll> (hei, 0));
    
    function<ll (ll)> fnd=[&](ll u){
        pool(j, hei, 0)if(a[psa[u][j]]) u=psa[u][j];

        return u;
    };
    
    loop(i, 1, q+1){
        ll tip;cin >> tip;
        if(tip==1){
            cin >> psa[i][0] >> a[i] >>c[i];
            loop(j, 1, hei) psa[i][j]=psa[psa[i][j-1]][j-1];
        }
        else if(tip==2){
            ll v, w;cin >> v >> w;
            ll sw=w;
            ll dn=0;
            while(w){
                ll u=fnd(v);
                ll kup=min(w, a[u]);
                w-=kup;
                a[u]-=kup;
                dn+= kup * c[u];
                if(u==v) break;
            }
            
            cout << sw-w <<" "<< dn<<endl;
        }
    }
}