Problem: Phoenix wonders what it is like to rob diamonds from a jewelry store!

There are n types of diamonds. The i-th type has weight w_i and value v_i. The store initially has a_i diamonds of the i-th type.

Each day, for q days, one of the following will happen: 

  1. A new shipment of k_i diamonds of type d_i arrive. 
  2. The store sells k_i diamonds of type d_i. 
  3. Phoenix wonders what will happen if he robs the store using a bag that can fit diamonds with total weight not exceeding c_i. If he greedily takes diamonds of the largest value that fit, how much value would be taken? If there are multiple diamonds with the largest value, he will take the one with minimum weight. If, of the diamonds with the largest value, there are multiple with the same minimum weight, he will take any of them. 



Of course, since Phoenix is a law-abiding citizen, this is all a thought experiment and he never actually robs any diamonds from the store. This means that queries of type 3 do not affect the diamonds in the store.

Input

The first line contains two integers n and q (1 ≤ n ≤ 2 ⋅ 10^5; 1 ≤ q ≤ 10^5) — the number of types of diamonds and number of days, respectively.

The next n lines describe each type of diamond. The i-th line will contain three integers a_i, w_i, and v_i (0 ≤ a_i ≤ 10^5; 1 ≤ w_i, v_i ≤ 10^5) — the initial number of diamonds of the i-th type, the weight of diamonds of the i-th type, and the value of diamonds of the i-th type, respectively.

The next q lines contain the queries. For each query, the first integer of each line is t (1 ≤ t ≤ 3) — the type of query.

If t=1, then two integers k_i, d_i follow (1 ≤ k_i ≤ 10^5; 1 ≤ d_i ≤ n). This means that a new shipment of k_i diamonds arrived, each of type d_i.

If t=2, then two integers k_i, d_i follow (1 ≤ k_i ≤ 10^5; 1 ≤ d_i ≤ n). This means that the store has sold k_i diamonds, each of type d_i. It is guaranteed that the store had the diamonds before they sold them.

If t=3, an integer c_i will follow (1 ≤ c_i ≤ 10^{18}) — the weight capacity of Phoenix's bag.

It is guaranteed that there is at least one query where t=3.

Output

Print the answer for each query of the third type (t=3).

Example

Input


3 5
2 3 4
1 5 1
0 2 4
3 6
1 3 3
3 10
2 2 3
3 30


Output


8
16
13

Note

For the first query where t=3, Phoenix can fit 2 diamonds of type 1, with total weight 6 and value 8.

For the second query where t=3, Phoenix will first fit in 3 diamonds of type 3, then one diamond of type 1 for a total weight of 9 and a value of 16. Note that diamonds of type 3 are prioritized over type 1 because type 3 has equal value but less weight.

For the final query where t=3, Phoenix can fit every diamond for a total value of 13.

Solution (in CPP):

Solution:
#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

*/