//#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4.1,sse4.2,avx,avx2,popcnt,tune=native")
#include <bits/stdc++.h>

#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(),(x).end()

using namespace std;

typedef long long LL;
typedef pair<int,int> PII;
typedef vector < int > VI;
typedef double D;

const int MN = 300005, LG = 20, inf = 1000000005, mod = 1000000007;
const LL INF = 1000000000000000005LL;

int A[MN], C[MN];
int hop[LG][MN];

int skacz(int v, int h)
{
	for(int s = LG - 1; s >= 0; --s)
	{
		int len = (1 << s);
		if(len <= h)
		{
			v = hop[s][v];
			h -= len;
		}
	}
	return v;
}

int nie_zero(int v)
{
	if(A[v] == 0)
		return -1;
	int ret = 0;
	for(int s = LG - 1; s >= 0; --s)
	{
		if(A[hop[s][v]])
		{
			ret += (1 << s);
			v = hop[s][v];
		}
	}
	return ret;
}

int main()
{
	int q;
	scanf("%d%d%d", &q, &A[0], &C[0]);
	for(int i = 1; i <= q; ++i)
	{
		int typ;
		scanf("%d", &typ);
		if(typ == 1)
		{
			scanf("%d%d%d", &hop[0][i], &A[i], &C[i]);
			for(int j = 1; j < LG; ++j)
				hop[j][i] = hop[j - 1][hop[j - 1][i]];
		}
		else
		{
			int v, w;
			scanf("%d%d", &v, &w);
			int b = 0;
			LL cena = 0LL;
			int up = nie_zero(v);
			for(int j = up; j >= 0; --j)
			{
				int kto = skacz(v, j);
				int ile = min(A[kto], w);
				b += ile;
				A[kto] -= ile;
				w -= ile;
				cena += 1LL * ile * C[kto];
				if(w == 0)
					break;
			}
			printf("%d %lld\n", b, cena);
			fflush(stdout);
		}
	}
}
