#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>

#define MAXN 300010
#define MAXM 600

using namespace std;

int n, a[MAXN], c[MAXN];
int father[MAXN], h[MAXN], block_root[MAXN];
int m = MAXM;

int st[MAXM + 10], top;
int st2[MAXN / MAXM + 10], top2;

pair<int, long long> check(int v, int w)
{
	long long total_cost = 0;
	int gold_num = 0;
	top = 0;
	int u = v;
	long long tmp;
	while (u ^ -1 && a[u]) {
		st[top++] = u;
		u = father[block_root[u]];
	}
	while (top && w) {
		u = st[--top];
		top2 = 0;
		while (a[u] && u ^ block_root[u]) {
			st2[top2++] = u;
			u = father[u];
		}
		if (a[u])
			st2[top2++] = u;
		while (top2 && w) {
			u = st2[--top2];
			tmp = min(w, a[u]);
			gold_num += tmp;
			total_cost += tmp * c[u];
			a[u] -= tmp;
			w -= tmp;
		}
	}
	return make_pair(gold_num, total_cost);
}

int main()
{
	//freopen("e.txt", "r", stdin);
	int q;
	int tp, p, v, w;
	while (cin >> q >> a[0] >> c[0]) {
		n = 1;
		father[0] = -1;
		h[0] = 0;
		block_root[0] = 0;
		for (int i = 1; i <= q; i++) {
			scanf("%d", &tp);
			if (2 ^ tp) {
				scanf("%d", &p);
				scanf("%d%d", a + i, c + i);
				father[i] = p;
				h[i] = h[p] + 1;
				if (h[i] % m) 
					block_root[i] = block_root[p];
				else
					block_root[i] = i;
			} else {
				scanf("%d%d", &v, &w);
				pair<int, long long> check_result = check(v, w);
				printf("%d %I64d\n", check_result.first, check_result.second);
				fflush(stdout);
			}
		}
	}
	return 0;
}