#include<bits/stdc++.h>
using namespace std;

#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define ps(x,y) fixed<<setprecision(y)<<x

typedef vector<int> vi;
typedef long long ll;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef unsigned long long ull;
typedef long double ld;

#ifndef ONLINE_JUDGE
#define debug(x) cerr << #x <<" "; _print(x); cerr << endl;
#else
#define debug(x)
#endif

void _print(ll t) {cerr << t;}
void _print(int t) {cerr << t;}
void _print(string t) {cerr << t;}
void _print(char t) {cerr << t;}
void _print(ld t) {cerr << t;}
void _print(double t) {cerr << t;}
void _print(ull t) {cerr << t;}

template <class T, class V> void _print(pair <T, V> p);
template <class T> void _print(vector <T> v);
template <class T> void _print(set <T> v);
template <class T, class V> void _print(map <T, V> v);
template <class T> void _print(multiset <T> v);
template <class T, class V> void _print(pair <T, V> p) {cerr << "{"; _print(p.fi); cerr << ","; _print(p.se); cerr << "}";}
template <class T> void _print(vector <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T> void _print(set <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T> void _print(multiset <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T, class V> void _print(map <T, V> v) {cerr << "[ "; for (auto i : v) {_print(i); cerr << " ";} cerr << "]";}

const int MOD = 1e9+7;
const ld PI = acos((ld)-1);
const int maxN = 3e5+5;

int table[maxN][21];
vector<int> adj[maxN];
vector<pii> vect(maxN);

void solve() {
    memset(table,-1,sizeof(table));
    int q,a,c;
    cin >> q >> a >> c;
    vect[0] = {a,c};
    for (int i = 1;i <= q;++i) {
        int type;
        cin >> type;
        if (type == 1) {
            int p;
            cin >> p >> a >> c;
            table[i][0] = p;
            vect[i] = {a,c};
            for (int j = 1;j < 21;++j) {
                if (table[i][j-1] != -1) {
                    table[i][j] = table[table[i][j-1]][j-1];
                } else {
                    break;
                }
            }
        } else {
            int v,w;
            cin >> v >> w;
            ll money = 0;
            int quant = 0;
            while (w) {
                int curr = v;
                for (int j = 20;j >= 0;--j) {
                    if (table[curr][j] != -1 && vect[table[curr][j]].first > 0) {
                        curr = table[curr][j];
                    }
                }
                int currQuant = min(w,vect[curr].first);
                quant += currQuant;
                money += (ll)currQuant*vect[curr].second;
                vect[curr].first -= currQuant;
                w -= currQuant;
                if (curr == v) break;
            }
            cout << quant << " " << money << '\n';
            cout.flush();
        }
    }

}

int main () {

#ifndef ONLINE_JUDGE
    freopen("input1.txt","r",stdin);
    freopen("output1.txt","w",stdout);
    freopen("Error.txt", "w", stderr);
#endif

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    return 0;
}

