//by the authority of GOD  author manhar singh sachdev//
#pragma GCC optimize("O3")
#pragma GCC target("sse4")
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define test int t; cin>>t; while(t--)
#define fio ios_base::sync_with_stdio(false); cin.tie(NULL);
const ll INF = 1000000000000000000;
#define endl "\n"
#define debug(v,n) for(int ii=0;ii<n;ii++){cout<<v[ii]<<" ";}cout<<endl;
#define fill(a,n,v) for(int i=0;i<n;i++)a[i]=v;
#define fill1(a,n,m,v) for(int i=0;i<n;i++){for(int j=0;j<m;j++)a[i][j]=v;}
#define maxheap priority_queue<ll>
#define minheap priority_queue<ll, vector<ll>, greater<ll>>
const int mod = 1000000007;

void rec(int ver,int lim,vector<vector<int>>&lifting,vector<int>&amount,int&amo,vector<ll>&price,ll&cost)
{
    if (lim==-1)
    {
        int tk = min(amo,amount[ver]);
        amo -= tk;
        amount[ver] -= tk;
        cost += price[ver]*tk;
    }
    else if (amo)
    {
        for (int i=lim;i>=0;i--)
        {
            if (lifting[i][ver]==-1)
                continue;
            if (amount[lifting[i][ver]])
                rec(lifting[i][ver],i-1,lifting,amount,amo,price,cost);
            if (!amo)
                break;
        }
        int tk = min(amo,amount[ver]);
        amo -= tk;
        amount[ver] -= tk;
        cost += price[ver]*tk;
    }
}

int main()
{
    #ifndef ONLINE_JUDGE
        freopen("input.txt","r", stdin);
        freopen("output.txt","w",stdout);
        freopen("Error.txt","w",stderr);
    #endif
    int q,a0,c0;
    cin>>q>>a0>>c0;
    vector<ll> price(q+1,-1);
    vector<int> amount(q+1,-1);
    int si = 20;
    price[0] = c0;
    amount[0] = a0;
    vector<vector<int>> lifting(si,vector<int>(q+1,-1));
    for (int node=1;node<q+1;node++)
    {
        int op;
        cin>>op;
        if (op == 1)
        {
            int par,gold,pr;
            cin>>par>>gold>>pr;
            lifting[0][node] = par;
            int now = par;
            for (int i=1;i<si;i++)
            {
                lifting[i][node] = lifting[i-1][now];
                now = lifting[i][node];
                if (now == -1)
                    break;
            }
            price[node] = pr;
            amount[node] = gold;
        }
        else
        {
            int ver,amo;
            cin>>ver>>amo;
            int amo1=amo;
            ll cost = 0;
            rec(ver,si-1,lifting,amount,amo,price,cost);
            cout<<amo1-amo<<" "<<cost<<endl;
        }
    }
    return 0;
}