#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using ull = unsigned long long;
constexpr ll MOD = 1000 * 1000 * 1000 + 7;
constexpr int ALPHABET_SIZE = 26;
constexpr ll INF = 1e18;
constexpr int DIGITS = 10;

int find_anc(int v, int d, const vector<int>& max_pow, const vector<vector<int>>& par) {
    if (d == 0) {
        return v;
    }
    int p = max_pow[d];
    if ((1 << p) == d) {
        return par[v][p];
    }
    int nxt = par[v][p];
    return find_anc(nxt, d - (1 << p), max_pow, par);
};

int main() {
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    vector<vector<int>> par(1);
    vector<int> a(1), c(1), d(1);
    int q;
    cin >> q >> a[0] >> c[0];

    constexpr int MAXQ = 300000;
    vector<int> max_pow(MAXQ + 1);
    for (int i = 0; (1 << i) <= MAXQ; ++i) {
        for (int j = (1 << i); j <= MAXQ && j < (1 << (i + 1)); ++j) {
            max_pow[j] = i;
        }
    }

    for (int i = 1; i <= q; ++i) {
        int t;
        cin >> t;
        if (t == 1) {
            par.resize(i + 1);
            d.resize(i + 1);
            a.resize(i + 1);
            c.resize(i + 1);
            int p;
            cin >> p >> a[i] >> c[i];
            par[i].push_back(p);
            while (true) {
                int l = par[i].size();
                int anc = par[i].back();
                if (par[anc].size() < l) {
                    break;
                }
                par[i].push_back(par[anc][l - 1]);
            }
            d[i] = d[p] + 1;
        } else {
            int v, w;
            cin >> v >> w;
            if (a[v] == 0) {
                cout << 0 << " " << 0 << endl;
                continue;
            }
            int min_d = 0, max_d = d[v] + 1;
            while (max_d - min_d > 1) {
                int m_d = (min_d + max_d) / 2;
                int u = find_anc(v, m_d, max_pow, par);
                if (a[u] == 0) {
                    max_d = m_d;
                } else {
                    min_d = m_d;
                }
            }
            int cur_d = min_d;
            ll ans = 0;
            int orig_w = w;
            while (cur_d >= 0 && w > 0) {
                int u = find_anc(v, cur_d, max_pow, par);
                if (a[u] >= w) {
                    ans += static_cast<ll>(w) * c[u];
                    a[u] -= w;
                    w = 0;
                } else {
                    ans += static_cast<ll>(a[u]) * c[u];
                    w -= a[u];
                    a[u] = 0;
                    --cur_d;
                }
            }
            cout << orig_w - w << " " << ans << endl;
        }
    }

    return 0;
}
