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>

#define eprintf(args...) fprintf(stderr, args)
#define rep(i, n) for (int i = 0; i < (int)(n); ++ i)

typedef long long ll;

const int mxn = 2e5 + 5;
const ll linf = 1LL << 60;

int n, q;

struct Jew {
	int a, v, w, i;

	inline bool operator < (const Jew &oth) const {
		return v != oth.v ? v > oth.v : w < oth.w;
	}
} vjew[mxn];

int rid[mxn];

ll lim[17];
int val[17][mxn];

struct SEG1 {
	static const int mxn = 1 << 18;

	ll sw[mxn << 1], sv[mxn << 1];

	void update(int x, int v) {
		int id = x;
		for (x += mxn; x; x >>= 1) {
			sw[x] += 1LL * v * vjew[id].w;
			sv[x] += 1LL * v * vjew[id].v;
		}
	}

	int query(int x, ll c) {
		ll nww = 0;
		int ox = x;
		for (x += mxn; x > 1; x >>= 1) {
			if (x & 1) {
				if (nww + sw[x] > c) break;
				nww += sw[x];
				++ x;
			}
		}
		if (ox != 0 && x == 1) return mxn;
		while (x < mxn) {
			if (nww + sw[x << 1] <= c) {
				nww += sw[x << 1];
				x = x << 1 | 1;
			} else {
				x = x << 1;
			}
		}
		return x - mxn;
	}

	std::pair <ll, ll> querysum(int l, int r) {
		ll w = 0, v = 0;
		for (l += mxn, r += mxn; l < r; l >>= 1, r >>= 1) {
			if (l & 1) w += sw[l], v += sv[l], ++ l;
			if (r & 1) -- r, w += sw[r], v += sv[r];
		}
		return {w, v};
	}
} seg1[17];

struct SEG2 {
	static const int mxn = 1 << 18;

	ll mn[mxn << 1], tag[mxn << 1];

	SEG2() { memset(mn, 0x3f, sizeof(mn)); memset(tag, 0, sizeof(tag)); }

	inline void push(int x, ll v) { mn[x] += v, tag[x] += v; }

	inline void pushdown(int x) { if (tag[x]) push(x << 1, tag[x]), push(x << 1 | 1, tag[x]), tag[x] = 0; }

	inline void pushup(int x) { mn[x] = std::min(mn[x << 1], mn[x << 1 | 1]); }

	void update(int l, int r, ll v) {
		l += mxn, r += mxn;
		for (int i = 18; i; -- i) {
			if (((l >> i) << i) != l) pushdown(l >> i);
			if (((r >> i) << i) != r) pushdown(r >> i);
		}
		int l0 = l, r0 = r;
		for (; l < r; l >>= 1, r >>= 1) {
			if (l & 1) push(l ++, v);
			if (r & 1) push(-- r, v);
		}
		for (int i = 1; i <= 18; ++ i) {
			if (((l0 >> i) << i) != l0) pushup(l0 >> i);
			if (((r0 >> i) << i) != r0) pushup(r0 >> i);
		}
	}

	int query(int x, ll c) {
		int ox = x;
		x += mxn;
		for (int i = 18; i; -- i) pushdown(x >> i);
		for (; x > 1; x >>= 1) {
			if (x & 1) {
				if (mn[x] <= c) break;
				++ x;
			}
		}
		if (ox != 0 && x == 1) return -1;
		if (mn[x] > c) return -1;
		for (; x < mxn; ) {
			pushdown(x);
			if (mn[x << 1] <= c) {
				x = x << 1;
			} else {
				x = x << 1 | 1;
			}
		}
		return x - mxn;
	}

	void set(int x, ll v) {
		x += mxn;
		for (int i = 18; i; -- i) pushdown(x >> i);
		mn[x] = v;
		for (int i = 1; i <= 18; ++ i) pushup(x >> i);
	}
} seg2[17];

void init(int n) {
}

void update(int x, int v) {
	rep(lv, 17) if (vjew[x].w < lim[lv]) {
		val[lv][x] += v;
		seg1[lv].update(x, v);
		if (lv) seg2[lv - 1].update(x + 1, mxn, 1LL * v * vjew[x].w);
		if (lv + 1 < 17 && vjew[x].w >= lim[lv + 1]) {
			if (!val[lv][x]) seg2[lv].set(x, linf);
			else seg2[lv].set(x, vjew[x].w + seg1[lv + 1].querysum(0, x).first);
		}
	}
}

ll query(int lv, int p, ll c) {
	if (lv == 17 || p >= n || c == 0) return 0;
	int np = std::min(n, seg1[lv].query(p, c));
	int op = p;
	int mp = lv ? seg2[lv - 1].query(p, c + seg1[lv].querysum(0, p).first) : -1;
	if (mp != -1) {
		c -= seg1[lv].querysum(p, mp).first + vjew[mp].w;
		return seg1[lv].querysum(op, mp).second + vjew[mp].v + query(lv + 1, mp + 1, c);
	}
	ll ans = 0;
	std::pair <ll, ll> pr = seg1[lv].querysum(op, np);
	ans += pr.second;
	c -= pr.first;
	if (np < n) {
		ll x = c / vjew[np].w;
		ans += x * vjew[np].v;
		c -= x * vjew[np].w;
		++ p;
	}
	return ans + query(lv + 1, np, c);
}

int main() {
	rep(i, 17) lim[i] = 1LL << (17 - i);
	scanf("%d %d", &n, &q);
	rep(i, n) scanf("%d %d %d", &vjew[i].a, &vjew[i].w, &vjew[i].v), vjew[i].i = i;
	std::sort(vjew, vjew + n);
	rep(i, n) rid[vjew[i].i] = i;
	init(n);
	rep(i, n) update(i, +vjew[i].a);
	while (q --) {
		int tp;
		scanf("%d", &tp);
		if (tp == 1) {
			int v, x;
			scanf("%d %d", &v, &x);
			x = rid[-- x];
			vjew[x].a += v;
			update(x, +v);
		} else if (tp == 2) {
			int v, x;
			scanf("%d %d", &v, &x);
			x = rid[-- x];
			vjew[x].a -= v;
			update(x, -v);
		} else if (tp == 3) {
			ll c;
			scanf("%lld", &c);
			printf("%lld\n", query(0, 0, c));
		}
	}
	return 0;
}