#include<bits/stdc++.h>
/*
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
*/
using namespace std;
/*
typedef tree<int,null_type, less<int>,rb_tree_tag,
        tree_order_statistics_node_update> indexed_set;
*/
#define pb push_back
#define ll long long
#define x1 first
#define y1 second
#define frb(i,a,b) for(ll (i)=(a);(i) <= (b); (i)+=(i)&-(i))
#define rfrb(i,a) for(ll (i)=(a);(i) > 0;(i)-=(i)&-(i))
#define fr(i,a,b) for(ll (i) = (a); (i) <= (b); (i)++)
#define rep(i,c) for(auto (i) : (c))
#define mini(a,b) (((a) < (b)) ? (a) : (b))
#define maxi(a,b) (((a) > (b)) ? (a) : (b))
#define par pair<ll,ll>
#define vp vector<par>
#define vi vector<ll>
#define dq deque<ll>
//indexed_set s;
///siempre ver las propiedades que se cumplen en los problemas    
///always see the properties of the problems
///siempre poner "\n" como endl
///----------------------------------------------------------------------------

const ll mod = 1e9+7;
const ll INF = 1e18;
ll n,t;
map<ll,ll>as;
ll ar[300005];
ll br[300005];
ll lca[300005][25];
ll lv[300005];

par comp(ll u, ll cant){
    ll v = u;
    ll res = 0, cap = 0;
    while(cap!=cant){
        v = u;
        for(ll i = 20; i>= 0;i--){
            if(ar[lca[v][i]]>0)v = lca[v][i];
        }
        if(ar[v] >= cant-cap){
            res += (cant-cap)*br[v];
            ar[v] -= cant-cap;
            cap = cant;
            return {res,cap};
        }else {
            res += ar[v]*br[v];
            cap += ar[v];
            ar[v] = 0;
        }
        if(v==u)return {res,cap}; 
    }
}

int main() {
    ios_base::sync_with_stdio(0);cin.tie(0);
    cout.setf(ios::fixed);cout.precision(0);
    ///freopen("a.in","r",stdin);
    ///freopen("a.out","w",stdout);
    cin>>t;
    ll cnt = 1;
    cin>>ar[1]>>br[1];
    ll a,b,c,d;
    as[0] = 1;
    lv[1] = 1;
    fr(i,1,t){
        cin>>a;
        if(a==1){
            cin>>b>>c>>d;
            cnt++;
            as[i] = cnt;
            ar[cnt] = c;
            br[cnt] = d;
            lv[cnt] = lv[as[b]]+1LL;
            lca[cnt][0] = as[b];
            fr(i,1,20){
                lca[cnt][i] = lca[lca[cnt][i-1]][i-1];
            }
            continue;
        }
        if(a==2){
            cin>>b>>c;
            par x = comp(as[b],c);
            cout<<x.second<<" "<<x.first<<endl;           
        }
    }
    return 0;
}