#include <bits/stdc++.h>

using namespace std;

#define mem(a,b) memset(a,b,sizeof(a))
#define FOR(i,j,k) for(ll i=j;i<=k;i++)
#define read        freopen("in.txt", "r", stdin)
#define write       freopen("out.txt", "w", stdout)
#define pf          prllf
#define sf(n)       scanf("%d", &n)
#define sff(a,b)    scanf("%d %d", &a, &b)
#define PB push_back
#define F first
#define S second
#define MP make_pair

typedef long long ll;
typedef pair<ll,ll> pii;

const ll inf = (1e9);
const ll M = 998244353 ;
const ll MAX = (3e5) + 5;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

ll n, p_tab[MAX][18], mb = 16, pa[MAX], val[MAX], cost[MAX], lev[MAX];
ll prin[MAX];

void make_sparce_table(ll x) {
    FOR(l,1,mb) {
        FOR(p,x,x) {
            ll my_pa = p_tab[p][l - 1];
            p_tab[p][l] = my_pa == -1 ? -1 : p_tab[my_pa][l - 1];
        }
    }
}

ll make_same(ll p,ll t_lev,ll bit) {
    if(lev[p] == t_lev) {
        return p;
    }

    if (p_tab[p][bit] != -1 && lev[p_tab[p][bit]] >= t_lev) {
        return make_same(p_tab[p][bit], t_lev, bit);
    }
    return make_same(p, t_lev, bit - 1);
}

int main() {
    ios::sync_with_stdio(false);
    //read;
    //write;
    ll q, t, v, c, w, p;

    cin >> q >> val[0] >> cost[0];
    mem(p_tab, -1);

    FOR(qq,1,q) {
        cin >> t;
        if(t == 1) {
            cin >> p >> v >> c;
            val[qq] = v;
            cost[qq] = c;
            p_tab[qq][0] = p;
            lev[qq] = lev[p] + 1;
            make_sparce_table(qq);
        } else {
            ll prin = 0, gold = 0;

            cin >> p >> v;

            while(v > 0) {
                ll st = 0, en = lev[p], mid, t_lev = (1e9);

                while(st <= en) {
                    mid = (st + en)>>1;
                    ll m_p = make_same(p, mid, mb);
                    if(val[m_p] == 0) {
                        st = mid + 1;
                    } else {
                        en = mid - 1;
                        t_lev = min(t_lev, mid);
                    }
                }

                if(t_lev == (1e9)) {
                    break;
                }

                ll c_node = make_same(p, t_lev, mb);
                ll can_take = min(v, val[c_node]);

                prin += (1ll * can_take * cost[c_node]);
                gold += can_take;
                val[c_node] -= can_take;
                v -= can_take;
            }
            cout << gold << " " << prin << endl;
        }
    }

    return 0;
}


