
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll>pii;
typedef vector<ll>vi;

#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rept(i,a,b) for(int i=(a);i<=(b);i++)
#define fi first
#define se second
#define mk(x,y) make_pair(x,y)
#define de(x) cout<<#x<<"="<<x<<"\n"
#define dd(x) cout<<#x<<"="<<x<<" "
#define pb(x) push_back(x)
#define all(x) x.begin(),x.end()
#define sz(x) (int)x.size()
#define lowbit(a) ((a)&-(a))
#define per(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define L i<<1
#define R i<<1|1
const int maxn = 3e5 + 5;
pii f[maxn];
int dp[maxn][20];
int main() {
	int a, b, c, d;
	int n;
	cin >> n >> a >> b;
	memset(dp, -1, sizeof(dp));
	f[0] = mk(a, b);
	for (int i = 1; i <= n; i++) {
		cin >> a;
		if (a == 1) {
			cin >> b >> c >> d;
			f[i] = mk(c, d);
			dp[i][0] = b;
			for (int j = 1; j < 20; j++) {
				if (dp[i][j - 1] != -1)
					dp[i][j] = dp[dp[i][j - 1]][j - 1];
			}
		}
		else {
			cin >> b >> c;
			int w = c;
			ll ans = 0;
			while (w) {
				int u = b;
				for (int i = 19; i >= 0; i--) {
					if (dp[u][i] == -1 || f[dp[u][i]].first == 0) continue;
					u = dp[u][i];
				}
				if (f[u].first == 0) break;
				if (w > f[u].first) {
					w -= f[u].first;
					ans += f[u].first * f[u].second;
					f[u].first = 0;
					continue;
				}
				f[u].first -= w;
				ans += w * f[u].second;
				w = 0;
				break;
			}
			cout << c - w << " " << ans << endl;
		}
	}
	return 0;
}
