#define _USE_MATH_DEFINES
#include<iostream>
#include<fstream>
#include<string>
#include<vector>
#include<utility>
#include<algorithm>
#include<climits>
#include<set>
#include<map>
#include<cmath>
#include<iomanip>
#include<iterator>
#include<queue>
#include<stack>
#include<cctype>
#include<deque>
#include<time.h>
#include<bitset>
#include<random>
#include<functional>
#include<unordered_set>
#include<unordered_map>
#include<random>
#include<numeric>
#include<chrono>
#include<sstream>
#include<valarray> 
#include<list>
#include<complex>
#include<cassert>

//by Skeef79

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

#pragma warning(disable : 4996)
#pragma comment(linker, "/STACK:16777216")
#define pb push_back
#define en '\n'
#define forn(i,n) for(int i = 0;i<n;i++)
#define for0(i,n) for(int i = 0;i<n;i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define vec vector
#define pii pair<int,int>
#define pll pair<ll,ll>
#define szof(x) int(x.size())
#define sqr(x) ((x)*(x))
#define debug(x) cerr<<#x<<" = "<<x<<'\n' 

using namespace std;

const int INF = 1000000000 + 1e8;
const ll LINF = 2000000000000000000;

//tonn, price
vec<pll>a;

vec<int>p;
vec<vec<int>>jump;
const int LOG = 20;
int n;

//tonn money

int findClosest(int v) {
	for (int j = LOG - 1; j >= 0; j--) {
		if (a[jump[v][j]].first > 0)
			v = jump[v][j];
	}
	return v;
}

pair<ll, ll> getAns(int v, ll w) {
	ll total = 0;
	ll price = 0;

	if (a[v].first == 0)
		return { 0,0 };

	while (total < w) {
		int u = findClosest(v);

		if (total + a[u].first < w) {
			total += a[u].first;
			price += a[u].first*a[u].second;
			a[u].first = 0;
		}
		else {
			ll diff = w - total;
			a[u].first -= diff;
			price += a[u].second*diff;
			total = w;
		}

		if (u == v) {
			break;
		}

	}

	return { total, price };
}

void solve() {
	ll q, a0, c0;
	cin >> q >> a0 >> c0;

	n = q + 10;
	a.resize(n);
	a[0] = { a0,c0 };
	p.resize(n, -1);
	p[0] = 0;
	
	jump = vec<vec<int>>(n, vec<int>(LOG));

	for (int v = 1; v <= q; v++) {
		int type;
		cin >> type;
		if (type == 1) {
			ll pr, ai, ci;
			cin >> pr >> ai >> ci;

			p[v] = pr;
			a[v] = { ai, ci };
			jump[v][0] = pr;
			for (int i = 1; i < LOG; i++)
				jump[v][i] = jump[jump[v][i - 1]][i - 1];
		}
		else {
			ll vv, w;
			cin >> vv >> w;
			auto ans = getAns(vv, w);
			cout << ans.first << ' ' << ans.second << endl;
		}
	}
}

int main() {
	/*srand(time(0));
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);*/

#ifdef _DEBUG	
	freopen("input.txt", "r", stdin);
#endif

	//freopen("hide.in", "r", stdin);

	int tst = 1;
	//cin >> tst;

	while (tst--)
		solve();
}