#include<bits/stdc++.h>
using namespace std;

typedef pair<int,int> pii;
typedef pair<string,int> psi;
typedef pair<int,string> pis;
typedef array<int,2> aii;
typedef array<int,3> aiii;
typedef array<int,4> aiiii;
typedef unsigned long long ull;
typedef long long int ll;
typedef array<ll,2> all;
typedef array<ll,3> alll;
typedef array<ll,4> allll;

#define pb push_back
#define ff first
#define ss second
#define MAX 300005
#define MOD 1000000007
#define INF 2e9
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
vector<aiii> adj[MAX];
int xMove[] = { 0,1,0,-1,1,1,-1,-1, 2, 2, -2, -2, 1, 1, -1, -1 };
int yMove[] = { 1,0,-1,0,1,-1,1,-1, 1, -1, 1, -1, 2, -2, 2, -2 };

aii gold[MAX];
int dp[MAX][19];

void calc_ancestors(int i)
{
    for(int j=1; j<=18; j++)
    {
        if(dp[i][j-1]!=-1)
            dp[i][j]=dp[dp[i][j-1]][j-1];
        else break;
    }
}

all buy_gold(int v, int w)
{
    ll cost=0,amount=0;
    while(w)
    {
        int cur=v;
        //cout<<"jwhfakhdaqd"<<endl;
        for(int j=18; j>=0; j--)
        {
            if(dp[v][j]!=-1 and gold[dp[v][j]][0]>0)
                v=dp[v][j];
        }

        ll mn=min(w,gold[v][0]);
        if(mn==0)
            break;

        w-=mn;
        gold[v][0]-=mn;
        cost+=mn*gold[v][1];
        amount+=mn;
        v=cur;
    }

    if(w)
    {
        ll mn=min(w,gold[v][0]);
        w-=mn;
        gold[v][0]-=mn;
        cost+=mn*gold[v][1];
        amount+=mn;
    }

    return {amount,cost};
}

int main()
{
    //freopen("input.in","r",stdin);
    //freopen("output.txt","w",stdout);
    cin.tie(0),cout.tie(0);
    ios_base::sync_with_stdio(0);
    cout.setf(ios::fixed);
    cout.precision(10);
    int TC=1;
    int n,m,k,q;

    //cin>>TC;
    for(int t1=1; t1<=TC; t1++)
    {
        memset(dp,-1,sizeof dp);
        cin>>q>>gold[0][0]>>gold[0][1];

        for(int i=1; i<=q; i++)
        {
            int t;
            cin>>t;
            if(t==1)
            {
                cin>>dp[i][0]>>gold[i][0]>>gold[i][1];
                calc_ancestors(i);
            }
            else
            {
                int v,w;
                cin>>v>>w;
                auto [a,c]=buy_gold(v,w);
                cout<<a<<" "<<c<<endl;
            }
        }
    }

    return 0;
}
