#include<bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define sz(x) (int)x.size()
#define ini(x, y) memset(x, y, sizeof(x));
#define pb push_back
#define fi first
#define se second
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int MOD = (int)1e9 + 7;
const int MAX = (int)2e9;
const double PI = acos(-1);

ll a[303030], c[303030];
int P[303030][20];
int main(void) {
	ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
	//freopen("input.txt", "r", stdin);
	int q; cin >> q >> a[0] >> c[0];
	for (int i = 1; i <= q; i++) {
		int n; cin >> n;
		if (n == 1) {
			int p; cin >> p >> a[i] >> c[i];
			P[i][0] = p;
			for (int j = 1; j <= 19; j++) {
				P[i][j] = P[P[i][j - 1]][j - 1];
			}
		}
		else {
			int v; ll w; cin >> v >> w;
			ll k1 = 0, k2 = 0;
			while (w > 0 && a[v] > 0) {
				int now = v;
				for (int j = 19; j >= 0; j--) {
					if (a[P[now][j]] > 0) {
						now = P[now][j];
					}
				}
				ll mi = min(a[now], w);
				a[now] -= mi;
				w -= mi;
				k1 += mi;
				k2 += mi * c[now];
			}
			cout << k1 << ' ' << k2 << endl;
		}
	}
}