import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, core.stdc.string;

int N, Q;
int[][] adj;
int[] parent;
long[] salary;

void dfs(int n, int prev, int s, int d) {
    salary[n] += s;
    if (d > 0) foreach (m; adj[n]) if (m != prev) dfs(m, n, s, d-1);
}
long dfs2(int n, int prev, int d) {
    long ret = salary[n];
    if (d > 0) foreach (m; adj[n]) if (m != prev) ret += dfs2(m, n, d-1);
    return ret;
}

void main() {
    auto s = readln.split.map!(to!int);
    N = s[0];
    Q = s[1];
    adj = new int[][](N);
    salary = new long[](N);
    fill(salary, 0);
    parent = new int[](N);
    parent[0] = -1;
    foreach (i; 0..N) {
        s = readln.split.map!(to!int);
        if (s[0] >= 0) adj[s[0]] ~= i;
        adj[i] ~= s[0];
        parent[i] = s[0];
        salary[i] = s[1];
    }



    foreach (i; 0..Q) {
        s = readln.split.map!(to!int);
        if (s[0] == 1) {
            dfs(s[1], parent[s[1]], s[3], s[2]);
        }
        else if (s[0] == 2) {
            dfs2(s[1], parent[s[1]], s[2]).writeln;
        }
        else {
            N += 1;
            adj ~= [s[1]];
            adj[s[1]] ~= N-1;
            parent ~= s[1];
            salary ~= s[2];
        }
    }
}
