#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <vector>

using Vertex = std::size_t;
using Adjacency = std::vector<std::vector<Vertex>>;

using Result = std::pair<std::uint32_t, std::uint64_t>;

Result take(Adjacency& ancestors, std::vector<std::uint32_t>& as,
		std::vector<std::uint32_t> const& cs, Vertex v, std::uint32_t w)
{
	//std::cout << '>' << v << ' ' << w << '\n';

	Result res{};
	while (!ancestors[v].empty() && w > 0) {
		Vertex anc = ancestors[v].back();
		if (as[anc] == 0) {
			ancestors[v].pop_back();
		}
		else {
			Result anc_res = take(ancestors, as, cs, anc, w);
			w -= anc_res.first;
			res.first += anc_res.first;
			res.second += anc_res.second;
		}
	}
	std::uint32_t amount = std::min(w, as[v]);
	as[v] -= amount;
	res.first += amount;
	res.second += 1ull * amount * cs[v];
	return res;
}

int main()
{
	std::size_t q;
	std::cin >> q;

	std::vector<std::uint32_t> as(q + 1), cs(q + 1);
	std::cin >> as[0] >> cs[0];

	Adjacency ancestors(q + 1);

	for (std::size_t i = 1; i <= q; ++i) {
		int t;
		std::cin >> t;
		if (t == 1) {
			std::size_t p;
			std::uint32_t a, c;
			std::cin >> p >> a >> c;
			ancestors[i].push_back(p);
			as[i] = a;
			cs[i] = c;
			std::size_t d = 0;
			while (d < ancestors[p].size()) {
				ancestors[i].push_back(ancestors[p][d]);
				p = ancestors[i].back();
				++d;
			}
		}
		else {
			std::size_t v;
			std::uint32_t w;
			std::cin >> v >> w;
			Result res = take(ancestors, as, cs, v, w);
			std::cout << res.first << ' ' << res.second << std::endl;
		}
	}

	return EXIT_SUCCESS;
}
