#include <bits/stdc++.h>
using namespace std;
#define all(x) x.begin(), x.end()
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
const int mxn = 3e5 + 5;
vector<int> adj[mxn], a(mxn), c(mxn), depth(mxn);
vector<vector<int>> up;
const int l = 20;
void process(int v, int w)
{
    // cerr << v << " line 13 " << w << endl;
    ll ans = 0;
    int taken = 0;
    while (taken <= w)
    {
        int lo = 0;
        int hi = depth[v];
        int rel = v;
        int rel_h = depth[v];
        while (lo <= hi)
        {
            int mid = lo + (hi - lo) / 2;
            int oldest_anc = v;
            if (v > 0)
            {
                for (int i = 0; i < l; i++)
                {
                    if ((mid >> i) & 1)
                    {
                        oldest_anc = up[oldest_anc][i];
                        if (oldest_anc <= 0)
                            break;
                    }
                }
            }
            if (a[oldest_anc] != 0)
            {
                if (rel_h > depth[oldest_anc])
                {
                    rel_h = depth[oldest_anc];
                    rel = oldest_anc;
                }
                lo = mid + 1;
            }
            else
            {
                hi = mid - 1;
            }
        }
        // cerr << taken << "  oldest anc  " << rel << " " << a[rel] << endl;
        if (taken + a[rel] >= w)
        {
            ans += (w - taken) * 1ll * c[rel];
            a[rel] -= (w - taken);
            taken = w;
            break;
        }
        else
        {
            ans += a[rel] * 1ll * c[rel];
            taken += a[rel];
            a[rel] = 0;
        }
        if (rel == v)
        {
            break;
        }
        // cerr << "curr available: ";
        // for (int i = 0; i <= 4; i++)
        //     cerr << a[i] << " ";
        // cerr << endl;
    }
    cout << taken << " " << ans << endl;
}
int main()
{
    up.assign(mxn, vector<int>(l + 1));
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int q;
    cin >> q >> a[0] >> c[0];
    depth[0] = 0;
    for (int i = 1; i <= q; i++)
    {
        int t;
        cin >> t;
        if (t == 1)
        {
            int p;
            cin >> p >> a[i] >> c[i];
            adj[p].push_back(i);
            adj[i].push_back(p);
            up[i][0] = p;
            for (int j = 1; j <= l; ++j)
                up[i][j] = up[up[i][j - 1]][j - 1];
            depth[i] = depth[up[i][0]] + 1;
        }
        else
        {
            int v, w;
            cin >> v >> w;
            process(v, w);
        }
    }

    return 0;
}
