                              //ABHISHEK AGRAWAL,BIT mesra//               
//Author: Abhishekagrawal  
//Date: 05/06/2021 
//Time: 16:07:19
#include<bits/stdc++.h>
using namespace std;
#define booga cout << "booga" << endl
#define int long long int
#define pb push_back  
#define f first
#define s second
#define mod 1000000007
#define pi (double)acos(-1.0)
#define what_is(x) cerr << #x << " is " << x << endl;
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#define safai(...) Clearing_out(__VA_ARGS__)
void Clearing_out() { return; }
 
template <typename Head, typename... Tail>
void Clearing_out(Head &H, Tail & ... T) {
	H.clear();
	Clearing_out(T...);
}
 

 
const int N=300040;int a[N],b[N],c[N],ans,sum;
int n;

int up[N][23];
int gold[N];
int cost[N];

void update(int node,int p){
 up[node][0]=p;
 for(int i=1;i<=22;i++){
  up[node][i]=up[up[node][i-1]][i-1];
 }
}
  

pair<int,int> query(int node,int w){
 int v=node;
 // binary search upwards
 int pay=0,bought=0;
 while(w>0 && gold[node]>0){
  for(int i=22;i>=0;i--){
   if(gold[up[node][i]])node=up[node][i];
  }
  int amt=min(w,gold[node]);
  gold[node]-=amt;
  pay+=amt*cost[node];
  w-=amt;
  bought+=amt;
  node=v;
 }
 return {bought,pay};
}

void testcase(){
  cin>>n;
  cin>>gold[1]>>cost[1];
  for(int i=2;i<=n+1;i++){
    int querytype ;
    cin>>querytype;
    if(querytype==1){
      int p,go,co;
      cin>>p>>gold[i]>>cost[i];
      update(i,p+1);
    } 
    else{
      int v,w;
      cin>>v>>w;
      auto p = query(v+1,w);
      cout<<p.f<<" "<<p.s<<endl;
    }
  }
  return;
}

int32_t main(){
  ios_base::sync_with_stdio(false);
  cin.tie(0);cout.tie(0); 
  /*Today's thought: Push yourself,because no one else is going to do it for you.*/
  /*SELECT * FROM World WHERE "Someone" LIKE '%You%'*/
  //g++ -o a acm.cpp -DENABLE_FILE_IO;./a
  int test=1;
  // cin>>test;  
  int t=0;
  while(test--){
    // cout<<"Case #"<<++t<<":"<<" ";
    testcase();
  } 
  cerr << "Time : " << 1000 *((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
  return 0;
}

