#include <iostream>
#include <vector>
#include <set>
#include <queue>
#include <algorithm>

using namespace std;
 
const int N = 300000 + 10;

long long q, a[N], c[N];
int p[N];
int back[N][20];

int get(int i, int j)
{
	int curr = 0;
	while (j > 0 && i != -1)
	{
		if (j&1)
			i = back[i][curr];
		j >>= 1;
		curr++;
	}
	return i;
}

int main()
{
	cin >> q >> a[0] >> c[0];
	
	for (int i = 0; i < N; i++)
	{
		for (int j = 0; j < 20; j++)
			back[i][j] = -1;
	}
	
	for (int j = 1; j <= q; j++)
	{
		int type;
		cin >> type;
		if (type == 1)
		{
			int pi, ai, ci;
			cin >> pi >> ai >> ci;
			p[j] = pi;
			a[j] = ai;
			c[j] = ci;
			back[j][0] = pi;
			for (int i = 1; i < 20; i++)
			{
				int v = back[j][i - 1];
				if (v == -1)
					back[j][i] = -1;
				else
					back[j][i] = back[v][i - 1];
			}
		}
		else
		{
			int v, w;
			cin >> v >> w;

			int l = 0, r = N;
			while (l < r)
			{
				int m = (l + r + 1) / 2;
				int ww = get(v, m);
				if (ww == -1)
					r = m - 1;
				else if (a[ww] > 0)
					l = m;
				else
					r = m - 1;
			}
			long long bought = 0, paid = 0;
			while (bought < w)
			{
				int ww = get(v, l);
				l--;
				long long add = min(w - bought, a[ww]);
				bought += add;
				a[ww] -= add;
				paid += 1LL * add * c[ww];
				if (ww == v)
					break;
			}
			cout << bought << " " << paid << endl;
		}
	}
	
	return 0;
}
