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 <stdio.h>
#include <sys/time.h>

#define N	200000
#define N_	(1 << 18)	/* N_ = pow2(ceil(log2(N))) */
#define LG	17	/* LG = floor(log2(10^5)) + 1 */
#define INF	0x3f3f3f3f3f3f3f3f

long long min(long long a, long long b) { return a < b ? a : b; }

unsigned int X;

void srand_() {
	struct timeval tv;

	gettimeofday(&tv, NULL);
	X = tv.tv_sec ^ tv.tv_usec;
	if (X % 2 == 0)
		X++;
}

int rand_() {
	return (X *= 3) >> 1;
}

long long aa[N]; int vv[N], ww[N], ii[N], inv[N], n;

void sort(int *ii, int l, int r) {
	while (l < r) {
		int i = l, j = l, k = r, i_ = ii[l + rand_() % (r - l)], tmp;

		while (j < k) {
			int c = vv[ii[j]] != vv[i_] ? vv[i_] - vv[ii[j]] : ww[ii[j]] - ww[i_];

			if (c == 0)
				j++;
			else if (c < 0) {
				tmp = ii[i], ii[i] = ii[j], ii[j] = tmp;
				i++, j++;
			} else {
				k--;
				tmp = ii[j], ii[j] = ii[k], ii[k] = tmp;
			}
		}
		sort(ii, l, i);
		l = k;
	}
}

long long vsm[LG + 1][N_ * 2], wsm[LG + 1][N_ * 2], wsm_[LG + 1][N_ * 2]; int n_;

void pul(int lg, int i) {
	int l = i << 1, r = l | 1;

	vsm[lg][i] = vsm[lg][l] + vsm[lg][r], wsm[lg][i] = wsm[lg][l] + wsm[lg][r];
	wsm_[lg][i] = min(wsm_[lg][l], wsm[lg][l] + wsm_[lg][r]);
}

void build() {
	int lg, i;

	n_ = 1;
	while (n_ < n)
		n_ <<= 1;
	for (lg = 0; lg <= LG; lg++) {
		for (i = 0; i < n_; i++) {
			long long a = aa[ii[i]];
			int v = vv[ii[i]], w = ww[ii[i]];

			if (i >= n)
				vsm[lg][n_ + i] = 0, wsm[lg][n_ + i] = 0, wsm_[lg][n_ + i] = INF;
			else if (w < (1 << lg))
				vsm[lg][n_ + i] = a * v, wsm[lg][n_ + i] = a * w, wsm_[lg][n_ + i] = INF;
			else
				vsm[lg][n_ + i] = 0, wsm[lg][n_ + i] = 0, wsm_[lg][n_ + i] = a == 0 ? INF : w;
		}
		for (i = n_ - 1; i > 0; i--)
			pul(lg, i);
	}
}

void update(int lg, int i) {
	long long a = aa[ii[i]];
	int v = vv[ii[i]], w = ww[ii[i]];

	if (w < (1 << lg))
		vsm[lg][n_ + i] = a * v, wsm[lg][n_ + i] = a * w, wsm_[lg][n_ + i] = INF;
	else
		vsm[lg][n_ + i] = 0, wsm[lg][n_ + i] = 0, wsm_[lg][n_ + i] = a == 0 ? INF : w;
	i += n_;
	while (i > 1)
		pul(lg, i >>= 1);
}

void update_(int i, int a) {
	int lg;

	aa[ii[i]] += a;
	for (lg = 0; lg <= LG; lg++)
		update(lg, i);
}

long long c, ans;

int jump(int lg, int i) {
	int l = i, r = n_ - 1;

	for (l += n_, r += n_; l <= r; l >>= 1, r >>= 1)
		if ((l & 1) == 1) {
			if (c >= wsm_[lg][l]) {
				while (l < n_)
					if (c >= wsm_[lg][l << 1 | 0])
						l = l << 1 | 0;
					else
						c -= wsm[lg][l << 1 | 0], ans += vsm[lg][l << 1 | 0], l = l << 1 | 1;
				l -= n_;
				c -= ww[ii[l]], ans += vv[ii[l]];
				return l + 1;
			} else if (c >= wsm[lg][l])
				c -= wsm[lg][l], ans += vsm[lg][l], l++;
			else {
				while (l < n_)
					if (c < wsm[lg][l << 1 | 0])
						l = l << 1 | 0;
					else
						c -= wsm[lg][l << 1 | 0], ans += vsm[lg][l << 1 | 0], l = l << 1 | 1;
				l -= n_;
				ans += c / ww[ii[l]] * vv[ii[l]], c %= ww[ii[l]];
				return l + 1;
			}
		}
	return n_;
}

int main() {
	int q, i;

	srand_();
	scanf("%d%d", &n, &q);
	for (i = 0; i < n; i++) {
		scanf("%lld%d%d", &aa[i], &ww[i], &vv[i]);
		ii[i] = i;
	}
	sort(ii, 0, n);
	for (i = 0; i < n; i++)
		inv[ii[i]] = i;
	build();
	while (q--) {
		int t;

		scanf("%d", &t);
		if (t == 1 || t == 2) {
			int a;

			scanf("%d%d", &a, &i), i--;
			update_(inv[i], t == 1 ? a : -a);
		} else {
			int lg, i;

			scanf("%lld", &c);
			ans = 0;
			for (lg = LG, i = 0; lg >= 0 && i < n_; lg--)
				i = jump(lg, i);
			printf("%lld\n", ans);
		}
	}
	return 0;
}