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;
const int N = 200005;
const int LOGN = 18;
const long long INF = 1.1e18;
struct Dat {
	long long a;
	int w, v, id;
} dat[N];
struct Node {
	long long sw[LOGN], sv[LOGN], aw[LOGN], av[LOGN];
} st[N * 4];
int n, q, idx[N];
void Upd(int i, int l, int r, int lf, int rg) {
	if (l == r) {
		for (int j = 1; j < LOGN; j++) {
			if (dat[l].w < (1 << j)) {
				st[i].sw[j] = dat[l].a * dat[l].w;
				st[i].sv[j] = dat[l].a * dat[l].v;
			} else {
				st[i].sw[j] = st[i].sv[j] = 0;
			}
			if (dat[l].w >= (1 << (j - 1)) && dat[l].w < (1 << j) && dat[l].a) {
				st[i].aw[j] = dat[l].w;
				st[i].av[j] = dat[l].v;
			} else {
				st[i].aw[j] = st[i].av[j] = INF;
			}
		}
		return;
	}
	int mid = (l + r) >> 1;
	if (lf <= mid) Upd(i << 1, l, mid, lf, rg);
	if (rg > mid) Upd(i << 1 | 1, mid + 1, r, lf, rg);
	for (int j = 1; j < LOGN; j++) {
		st[i].sw[j] = st[i << 1].sw[j] + st[i << 1 | 1].sw[j];
		st[i].sv[j] = st[i << 1].sv[j] + st[i << 1 | 1].sv[j];
		if (st[i << 1].aw[j] < st[i << 1].sw[j - 1] + st[i << 1 | 1].aw[j]) {
			st[i].aw[j] = st[i << 1].aw[j];
			st[i].av[j] = st[i << 1].av[j];
		} else {
			st[i].aw[j] = st[i << 1].sw[j - 1] + st[i << 1 | 1].aw[j];
			st[i].av[j] = st[i << 1].sv[j - 1] + st[i << 1 | 1].av[j];
		}
	}
}
void query(int i, int l, int r, int j, int &pos, long long &cw, long long &cv) {
	if (pos == l && st[i].sw[j] <= cw) {
		cw -= st[i].sw[j];
		cv += st[i].sv[j];
		pos = r + 1;
		return;
	}
	if (l == r) return;
	int mid = (l + r) >> 1;
	if (pos <= mid) query(i << 1, l, mid, j, pos, cw, cv);
	if (pos > mid) query(i << 1 | 1, mid + 1, r, j, pos, cw, cv);
}
int Finda(int i, int l, int r, int j, int &pos, long long &cw) {
	if (pos == l) {
		if (st[i].aw[j] > cw) {
			cw -= st[i].sw[j - 1];
			if (cw >= 0) pos = r + 1;
			return -1;
		} else if (l == r) {
			assert(cw >= st[i].aw[j]);
			return l;
		}
	}
	int mid = (l + r) >> 1, ret = -1;
	if (pos <= mid) ret = Finda(i << 1, l, mid, j, pos, cw);
	if (ret != -1) return ret;
	if (pos > mid) ret = Finda(i << 1 | 1, mid + 1, r, j, pos, cw);
	return ret;
}
int Finda(int j, int pos, long long cw) {
	return Finda(1, 1, n, j, pos, cw);
}
void querysum(int i, int l, int r, int j, int lf, int rg, long long &cw, long long &cv) {
	if (lf <= l && r <= rg) {
		cw -= st[i].sw[j];
		cv += st[i].sv[j];
		return;
	}
	int mid = (l + r) >> 1;
	if (lf <= mid) querysum(i << 1, l, mid, j, lf, rg, cw, cv);
	if (rg > mid) querysum(i << 1 | 1, mid + 1, r, j, lf, rg, cw, cv);
}
long long query(long long c) {
	int pos = 1;
	long long ret = 0;
	for (int i = LOGN - 1; i > 0; i--) {
		query(1, 1, n, i, pos, c, ret);
		if (pos > n) break;
		long long cur = min(dat[pos].a, c / dat[pos].w);
		c -= cur * dat[pos].w;
		ret += cur * dat[pos].v;
		pos++;
		if (pos > n) break;
		int npos = Finda(i, pos, c);
		if (npos != -1) {
			if (pos < npos) querysum(1, 1, n, i - 1, pos, npos - 1, c, ret);
			c -= dat[npos].w;
			ret += dat[npos].v;
			pos = npos + 1;
			if (pos > n) break;
		}
	}
	return ret;
}
int main() {
	scanf("%d%d", &n, &q);
	for (int i = 1; i <= n; i++) {
		scanf("%lld%d%d", &dat[i].a, &dat[i].w, &dat[i].v);
		dat[i].id = i;
	}
	sort(dat + 1, dat + 1 + n, [](Dat x, Dat y) {
		return x.v != y.v ? x.v > y.v : x.w < y.w;
	});
	for (int i = 1; i <= n; i++) idx[dat[i].id] = i;
	Upd(1, 1, n, 1, n);
	while (q--) {
		int ty;
		scanf("%d", &ty);
		if (ty == 1) {
			int k, d;
			scanf("%d%d", &k, &d);
			d = idx[d];
			dat[d].a += k;
			Upd(1, 1, n, d, d);
		} else if (ty == 2) {
			int k, d;
			scanf("%d%d", &k, &d);
			d = idx[d];
			dat[d].a -= k;
			Upd(1, 1, n, d, d);
		} else {
			long long c;
			scanf("%lld", &c);
			printf("%lld\n", query(c));
		}
	}
	return 0;
}