2 8
2 15 400
1 13 100
3 26
3 27
3 28
3 29
3 30
3 31
3 32
3 33
 3 8
2 15 400
1 1 200
1 13 100
3 26
3 27
3 28
3 29
3 30
3 31
3 32
3 33

400
400
500
500
800
800
800
800
 600
600
600
700
800
1000
1000
1000

#include <bits/stdc++.h>

using ll = long long;
const int maxn = 2e5 + 5;
const int LIM = 17;
const ll inf = 1e18 + 7;

class Diamond {
public:
    ll a;
    int w, v, id;
    Diamond(ll _a = 0, int _w = 0, int _v = 0, int _id = 0) : a(_a), w(_w), v(_v), id(_id) {}
    bool operator < (const Diamond &rhs) const {
        if(v != rhs.v) return v > rhs.v;
        return w < rhs.w;
    }
};

class Seg {
public:
    int k;
    class Node {
    public:
        ll sumw, sumv;
        int w, v;
        ll one_w, one_v;
        Node(ll _sumw = 0, ll _sumv = 0, int _w = 0, int _v = 0, ll _one_w = inf, ll _one_v = inf) : 
            sumw(_sumw), sumv(_sumv), w(_w), v(_v), one_w(_one_w), one_v(_one_v) {}
    } t[maxn * 4];

    #define ls (p << 1)
    #define rs (p << 1 | 1)
    #define mid ((l + r - 1) / 2)
    void pushup(int p) {
        t[p].sumw = t[ls].sumw + t[rs].sumw;
        t[p].sumv = t[ls].sumv + t[rs].sumv;
        if(t[ls].one_w < t[ls].sumw + t[rs].one_w) {
            t[p].one_w = t[ls].one_w;
            t[p].one_v = t[ls].one_v;
        } else {
            t[p].one_w = t[ls].sumw + t[rs].one_w;
            t[p].one_v = t[ls].sumv + t[rs].one_v;
        }
    }
    Node gen_node(int l, const std::vector<Diamond> &dia) {
        Node tmp;
        if(dia[l].w < (1 << k)) {
            tmp = Node(1ll * dia[l].w * dia[l].a, 1ll * dia[l].v * dia[l].a, dia[l].w, dia[l].v);
        } else if(dia[l].a > 0 && dia[l].w >= (1 << k) && dia[l].w < (1 << (k + 1))) {
            tmp = Node(0, 0, 0, dia[l].v, dia[l].w);
        }
        return tmp;
    }
    void build(int l, int r, int p, const std::vector<Diamond> &dia) {
        if(l + 1 == r) {
            t[p] = Node();
            t[p] = gen_node(l, dia);
            return;
        }
        build(l, mid + 1, ls, dia);
        build(mid + 1, r, rs, dia);
        pushup(p);
    }
    void modify(int l, int r, int p, int pos, const std::vector<Diamond> &dia) {
        if(l + 1 == r) {
            t[p] = Node();
            t[p] = gen_node(l, dia);
            return;
        }
        if(pos <= mid) modify(l, mid + 1, ls, pos, dia);
        else modify(mid + 1, r, rs, pos, dia);
        pushup(p);
    }
    std::pair<ll, std::pair<ll, int>> query(int l, int r, int ql, int qr, int p, ll V) {
        if(ql >= qr) return std::make_pair(0, std::make_pair(V, ql));
        if(ql <= l && qr >= r) {
            if(t[p].sumw <= V) return std::make_pair(t[p].sumv, std::make_pair(V - t[p].sumw, r));
            if(l + 1 == r) {
                // if(t[p].w == 0) {
                //     std::cout << "FUCK" << std::endl;
                //     std::cout << t[p].sumw << std::endl;
                //     std::cout << V << std::endl;
                // }
                if(t[p].sumw <= V) return std::make_pair(t[p].sumv, std::make_pair(V - t[p].sumw, r));
                return std::make_pair(V / t[p].w * t[p].v, std::make_pair(V % t[p].w, r));
            }
            if(V >= t[ls].sumw) {
                std::pair<ll, std::pair<ll, int>> rnt = query(mid + 1, r, mid + 1, r, rs, V - t[ls].sumw);
                rnt.first += t[ls].sumv;
                return rnt;
            } else return query(l, mid + 1, l, mid + 1, ls, V);
        }
        if(qr <= mid + 1) return query(l, mid + 1, ql, qr, ls, V);
        else if(ql > mid) return query(mid + 1, r, ql, qr, rs, V);
        else {
            std::pair<ll, std::pair<ll, int>> L = query(l, mid + 1, ql, mid + 1, ls, V);
            if(L.second.second <= mid) return L;
            std::pair<ll, std::pair<ll, int>> R = query(mid + 1, r, mid + 1, qr, rs, L.second.first);
            R.first += L.first;
            return R;
        }
    }
    std::pair<ll, int> query_one_pos(int l, int r, int ql, int qr, int p, ll V) {
        // if(ql >= qr) return std::make_pair(0, ql);
        if(ql <= l && qr >= r) {
            if(t[p].one_w > V) return std::make_pair(t[p].sumw, r);
            if(l + 1 == r) return std::make_pair(t[p].sumw, l);
            if(t[ls].one_w <= V) return query_one_pos(l, mid + 1, l, mid + 1, ls, V);
            else {
                std::pair<ll, int> rnt = query_one_pos(mid + 1, r, mid + 1, r, rs, V - t[ls].sumw);
                rnt.first += t[ls].sumw;
                return rnt;
            }
        }
        if(qr <= mid + 1) return query_one_pos(l, mid + 1, ql, qr, ls, V);
        else if(ql > mid) return query_one_pos(mid + 1, r, ql, qr, rs, V);
        else {
            std::pair<ll, int> L = query_one_pos(l, mid + 1, ql, mid + 1, ls, V);
            if(L.second <= mid) return L;
            std::pair<ll, int> R = query_one_pos(mid + 1, r, mid + 1, qr, rs, V - L.first);
            R.first += L.first;
            return R;
        }
    }
    void print(int l, int r, int p) {
        std::cout << "one_w[" << l << ", " << r << "] = " << t[p].one_w << std::endl;
        if(l + 1 == r) return;
        print(l, mid + 1, ls);
        print(mid + 1, r, rs);
    }
    #undef ls
    #undef rs
    #undef mid
} SEG[20];

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    int n, q;
    std::cin >> n >> q;
    std::vector<Diamond> dia(n);
    for(int i = 0; i < n; i++) {
        ll a;
        int w, v;
        std::cin >> a >> w >> v;
        dia[i] = Diamond(a, w, v, i);
    }
    std::sort(dia.begin(), dia.end());
    std::vector<int> id(n);
    for(int i = 0; i < n; i++) {
        id[dia[i].id] = i;
    }
    for(int i = 1; i <= LIM; i++) SEG[i].k = i;
    for(int i = 1; i <= LIM; i++) SEG[i].build(0, n, 1, dia);

    // std::cout << SEG[3].query_one_pos(0, n, 2, n, 1, 15).second << std::endl;
    // SEG[3].print(0, n, 1);
    
    // std::cout << "OK" << std::endl;

    while(q--) {
        int type, k, d;
        std::cin >> type;
        // std::cout << type << std::endl;
        if(type == 1) {
            std::cin >> k >> d;
            d--;
            dia[id[d]].a += k;
            for(int i = 1; i <= LIM; i++) {
                SEG[i].modify(0, n, 1, id[d], dia);
            }
        } else if(type == 2) {
            std::cin >> k >> d;
            d--;
            dia[id[d]].a -= k;
            for(int i = 1; i <= LIM; i++) {
                SEG[i].modify(0, n, 1, id[d], dia);
            }
        } else {
            ll c, ans = 0;
            int l = 0, r = 0;
            std::cin >> c;

            // for(int i = 1; i <= LIM; i++) {
            //     SEG[i].k = i;
            //     SEG[i].build(0, n, 1, dia);
            //     std::cout << "OK" << std::endl;
            // }

            // std::cout << n << " " << 1 << std::endl;
            // for(auto v : dia) std::cout << v.a << " " << v.w << " " << v.v << std::endl;
            // std::cout << 3 << " " << c << std::endl;

            std::pair<ll, std::pair<ll, int>> init = SEG[LIM].query(0, n, 0, n, 1, c);
            // std::cout << "ok" << std::endl;
            // std::cout << n << " " << 1 << std::endl;
            // for(auto v : dia) {
            //     std::cout << v.a << " " << v.w << " " << v.v << std::endl;
            // }
            // std::cout << c << std::endl;
            c = init.second.first;
            l = init.second.second;
            ans = init.first;
            // assert(c < (1 << LIM) || l >= n);
            for(int i = LIM; i >= 1; i--) {
                if(l >= n) break;
                r = SEG[i].query_one_pos(0, n, l, n, 1, c).second;
                // std::cout << i << " " << "ok" << std::endl;
                // std::cout << l << " " << r << " " << c << std::endl;
                if(r < n) {
                    if(l < r) {
                        init = SEG[i].query(0, n, l, r, 1, c);
                        c = init.second.first;
                        l = init.second.second;
                        ans += init.first;
                    }
                    if(l != r) std::cout << "NO" << std::endl;
                    // std::cout << "------------------" << std::endl;
                    // std::cout << dia[id[r]].w << std::endl;
                    // std::cout << id[r] << std::endl;
                    // std::cout << "------------------" << std::endl;
                    // if(c < dia[id[r]].w) {
                    //     std::cout << c << std::endl;
                    //     std::cout << "FUCK" << std::endl;
                    //     std::cout << dia[id[r]].w << " " << (1 << i) << " " << (1 << (i + 1)) << std::endl;
                    // }
                        c -= dia[r].w;
                        ans += dia[r].v;
                        l = r + 1;
                } else {
                    // std::cout << "ok12" << std::endl;
                    // std::cout << c << std::endl;
                    init = SEG[i].query(0, n, l, n, 1, c);
                    // std::cout << "ok11" << std::endl;
                    c = init.second.first;
                    l = init.second.second;
                    ans += init.first;
                }
                // assert(c < (1 << i) || l >= n);
            }
            std::cout << ans << std::endl;
        }
    }
    return 0;
}
/*
1 1 100

*/