import std.stdio;
import std.ascii;
import std.algorithm;
static import core.stdc.stdio;

long[300_000+2] a;
long[300_000+2] c;

int main()
{
    int[][] parent = new int[][](300_000+2, 20);
    int q = readInt!int;
    a[0] = readInt!long;
    c[0] = readInt!long;
    parent[0][] = -1;
    int getNthParent(int v, int n)
    {
        int i = 0;
        while (n)
        {
            if (n & 1)
                v = parent[v][i];
            n >>= 1;
            i++;
        }
        return v;
    }
    foreach(i; 1 .. q + 1)
    {
        int type = readInt!int;
        if (type == 1)
        {
            int pi = readInt!int;
            long ai = readInt!long;
            long ci = readInt!long;
            parent[i][0] = pi;
            foreach(j; 1 .. 20)
            {
                if (parent[i][j - 1] > 0)
                    parent[i][j] = parent[parent[i][j - 1]][j - 1];
                else parent[i][j] = -1;
            }
            a[i] = ai;
            c[i] = ci;
        }
        else
        {
            int vi = readInt!int;
            long wi = readInt!long;
            int root = vi;
            int no = 0;
            long spent = 0;
            long bought = 0;
            foreach_reverse(j; 0 .. 20)
            {
                int possibleParent = parent[root][j];
                if (possibleParent < 0) continue;
                if (a[possibleParent] > 0)
                {
                    root = possibleParent;
                    no += (long(1) << j);
                }
            }
            debug writeln("for node ", vi, " root is ", root, " depth = ", no);
            while (wi > 0 && no >= 0)
            {
                int p = getNthParent(vi, no);
                debug writeln("Now is ", no, " ", p, " ap = ", a[p], " wi = ", wi);
                long taken = min(wi, a[p]);
                wi -= taken;
                bought += taken;
                spent += taken * c[p];
                a[p] -= taken;
                no--;
            }
            writeln(bought, " ", spent);
            stdout.flush;
        }
    }
    return 0;
}


/* INPUT ROUTINES */
int currChar;
static this()
{
    currChar = core.stdc.stdio.getchar();
}
char topChar()
{
    return cast(char) currChar;
}
void popChar()
{
    currChar = core.stdc.stdio.getchar();
}
auto readInt(T)()
{
    T num = 0;
    int sgn = 0;
    while (topChar.isWhite) popChar;
    while (topChar == '-' || topChar == '+') { sgn ^= (topChar == '-'); popChar; }
    while (topChar.isDigit) { num *= 10; num += (topChar - '0'); popChar; }
    if (sgn) return -num; return num;
}
string readString()
{
    string res = "";
    while (topChar.isWhite) popChar;
    while (!topChar.isWhite) { res ~= topChar; popChar; }
    return res;
}
/**MODULAR SYSTEM*/
struct Z(immutable long m)
{
    long rep;
    this(long num)
    {
        rep = num;
    }
    Z!m opBinary(string operator)(Z!m rhs)
    {
        static if (operator == "+")
        {
            long result = rhs.rep + this.rep;
            if (result >= m) result -= m;
            return Z!m(result);
        }
        else static if (operator == "-")
        {
            long result = this.rep - rhs.rep;
            if (result < 0) result += m;
            return Z!m(result);
        }
        else static if (operator == "*")
        {
            long result = this.rep * rhs.rep;
            if (result >= m) result %= m;
            return Z!m(result);
        } else static assert(text("Operator ", operator, " not supported"));
    }
    Z!m opBinary(string operator)(long exponent) if (operator == "^^")
    {
        assert(exponent >= 0);
        Z!m base = this;
        Z!m result = 1;
        while (exponent)
        {
            if (exponent & 1)
                result = result * base;
            base = base * base;
            exponent >>= 1;
        }
        return result;
    }
    invariant
    {
        assert(rep >= 0 && rep < m);
    }
}
