/* Rupinder Singh Khokhar */
#include <bits/stdc++.h>
using namespace std;
#define fo(i, n) for (i = 0; i < n; i++)
#define Fo(i, k, n) for (i = k; k < n ? i < n : i > n; k < n ? i += 1 : i -= 1)
#define ll long long
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << ", " << #y << "=" << y << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for (auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
typedef pair<int, int> pii;
typedef pair<ll, ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vpii;
typedef vector<vi> vii;
typedef vector<vl> vll;

int get(vii &re, int i, int st) {
    for (int j = 17; j >= 0; j--) {
        if (st - (1<<j) >= 0) {
            st -= (1 << j);
            i = re[i][j];
        }
    }
    return i;
}
int main()
{
 ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
 srand(chrono::high_resolution_clock::now().time_since_epoch().count());
 
 int q;
 cin >> q;
 vi p(q + 1, -1), a(q + 1, -1);
 vl c(q + 1, -1);
 cin>> a[0] >> c[0];
 p[0] = 0;
 vii re(q + 1, vi(18));
 for (int i = 1; i <= q; i++) {
     int x;
     cin >> x;
     if (x == 1) {
         cin >> p[i] >> a[i] >> c[i];
         re[i][0] = p[i];
         for (int j = 1; j <= 17; j++) {
             re[i][j] = get(re, p[i], (1 << j) - 1);
         }
     } else {
         int v, w;
         cin >> v >> w;
         ll mo = 0, bo = 0;
         while (w > 0 && a[p[v]] > 0) {
             int vc = v;
             for (int j = 17; j >= 0; j--)
             {
                 if (a[re[vc][j]] > 0)
                 {
                     vc = re[vc][j];
                 }
            }
            int curBo = min(a[vc], w);
            bo +=curBo;
            mo += curBo * c[vc];
            w -= curBo;
            a[vc] -= curBo;
         }
         if (w > 0) {
             int lBo = min(a[v], w);
             mo += lBo * c[v];
             bo += lBo;
             a[v] -= lBo;
         }
         cout << bo << " " << mo << endl;
     }
 }

 return 0;
}