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 namespace std;
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define loop(i, a) for (int i = 0; i < (a); ++i)
#define cont(i, a) for (int i = 1; i <= (a); ++i)
#define circ(i, a, b) for (int i = (a); i <= (b); ++i)
#define range(i, a, b, c) for (int i = (a); (c) > 0 ? i <= (b) : i >= (b); i += (c))
#define parse(it, x) for (auto &it : (x))
#define pub push_back
#define pob pop_back
#define emb emplace_back
#define mak make_pair
#define mkt make_tuple
typedef long long ll;
typedef long double lf;
const int Inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3fll;

const int maxn = 1 << 18, mxlog = 18;

struct CF1515I {
    ll a, w, v;
    int id;
    bool operator < (const CF1515I &x) const {
        return mak(-v, w) < mak(-x.v, x.w);
    }
} s[maxn];

int n, q;

struct SegtreeH {
    ll ws[maxn << 1], vs[maxn << 1];
    void inline add(int a, int x) {
        int p = a;
        for (a += maxn; a; a >>= 1) {
            ws[a] += s[p].w * x;
            vs[a] += s[p].v * x;
        }
    }
    ll inline sumw(int l, int r) {
        ll res = 0;
        for (l += maxn, r += maxn + 1; l < r; l >>= 1, r >>= 1) {
            if (l & 1) res += ws[l++];
            if (r & 1) res += ws[--r];
        }
        return res;
    }
    int inline find(int l, int r, ll &val, ll &res, int now = 1, int nl = 0, int nr = maxn - 1) {
        if (nl > r || nr < l || l > r) return -1;
        if (nl >= l && nr <= r && ws[now] <= val) {
            val -= ws[now]; res += vs[now];
            return -1;
        }
        if (nl == nr) return nl;
        int m = (nl + nr) >> 1;
        int v = find(l, r, val, res, now << 1, nl, m);
        if (!~v) v = find(l, r, val, res, now << 1 | 1, m + 1, nr);
        return v;
    }
} s1[mxlog + 1];

struct SegtreeHe {
    ll mn[maxn << 1], tg[maxn << 1];
    void inline init() { memset(mn, Inf, sizeof(mn)); }
    void inline push(int a, ll x) { mn[a] += x; tg[a] += x; }
    void inline pd(int now) {
        if (tg[now]) {
            push(now << 1, tg[now]);
            push(now << 1 | 1, tg[now]);
            tg[now] = 0;
        }
    }
    void inline pu(int now) { mn[now] = min(mn[now << 1], mn[now << 1 | 1]); }
    void inline add(int l, int r, ll x) {
        l += maxn; r += maxn + 1;
        int cl = l, cr = r;
        range(i, mxlog, 1, -1) {
            if ((l >> i << i) != l) pd(l >> i);
            if ((r >> i << i) != r) pd(r >> i);
        }
        for (; l < r; l >>= 1, r >>= 1) {
            if (l & 1) push(l++, x);
            if (r & 1) push(--r, x);
        }
        l = cl; r = cr;
        cont(i, mxlog) {
            if ((l >> i << i) != l) pu(l >> i);
            if ((r >> i << i) != r) pu(r >> i);
        }
    }
    void inline change(int a, ll x) {
        a += maxn;
        range(i, mxlog, 1, -1) pd(a >> i);
        mn[a] = x;
        cont(i, mxlog) pu(a >> i);
    }
    int inline find(int l, int r, ll val, int now = 1, int nl = 0, int nr = maxn - 1) {
        if (nl > r || nr < l || l > r) return -1;
        if (nl >= l && nr <= r && mn[now] > val) return -1;
        if (nl == nr) return nl;
        int m = (nl + nr) >> 1; pd(now);
        int v = find(l, r, val, now << 1, nl, m);
        if (!~v) v = find(l, r, val, now << 1 | 1, m + 1, nr);
        return v;
    }
} s2[mxlog + 1];

int tp[maxn], dy[maxn];

void inline init(int lg) {
    s2[lg].init();
    loop(i, n) if (s[i].w < (1 << lg)) s1[lg].add(i, s[i].a);
    loop(i, n) {
        if (tp[i] != lg || !s[i].a) s2[lg].change(i, INF);
        else s2[lg].change(i, s[i].w + s1[lg].sumw(0, i - 1));
    }
}

void inline modify(int i, ll x) {
    loop(lg, mxlog + 1) if (s[i].w < (1 << lg)) {
        s1[lg].add(i, x);
        s2[lg].add(i, maxn - 1, x * s[i].w);
    }
    int lg = tp[i];
    if (!s[i].a) s2[lg].change(i, s[i].w + s1[lg].sumw(0, i - 1));
    s[i].a += x;
    if (!s[i].a) s2[lg].change(i, INF);
}

ll query(ll c) {
    ll ans = 0;
    int pos = 0;
    range(lg, mxlog, 0, -1) if (c >= (1 << lg)) {
        ll wc = c - (1 << lg);
        int rpos = s2[lg].find(pos, maxn - 1, c + s1[lg].sumw(0, pos - 1));
        if (!~rpos) rpos = maxn;
        pos = s1[lg].find(pos, rpos - 1, wc, ans);
        if (!~pos) pos = rpos;
        c = wc + (1 << lg);
        if (pos < n) {
            ll d = min(s[pos].a, c / s[pos].w);
            ans += d * s[pos].v;
            c -= d * s[pos++].w;
        }
        if (pos >= n) break;
    }
    return ans;
}

int main() {
    scanf("%d%d", &n, &q);
    loop(i, n) scanf("%lld%lld%lld", &s[i].a, &s[i].w, &s[i].v), s[i].id = i + 1;
    sort(s, s + n);
    loop(i, n) {
        while (s[i].w >= (1 << (tp[i] + 1))) ++tp[i];
        dy[s[i].id] = i;
    }
    loop(i, mxlog + 1) init(i);
    while (q--) {
        int tp; scanf("%d", &tp);
        if (tp <= 2) {
            int k, d; scanf("%d%d", &k, &d);
            d = dy[d]; if (tp == 2) k = -k;
            modify(d, k);
        }
        else {
            ll c; scanf("%lld", &c);
            printf("%lld\n", query(c));
        }
    }
    return 0;
}
// 弔题，烦死了
// 问候出题人全家