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 rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

struct FT {
	vector<ll> s;
	FT(int n) : s(n) {}
	void update(int pos, ll dif) { // a[pos] += dif
		for (; pos < sz(s); pos |= pos + 1) s[pos] += dif;
	}
	ll query(int pos) { // sum of values in [0, pos)
		ll res = 0;
		for (; pos > 0; pos &= pos - 1) res += s[pos-1];
		return res;
	}
	int lower_bound(ll sum) {// min pos st sum of [0, pos] >= sum
		// Returns n if no sum is >= sum, or -1 if empty sum is.
		if (sum <= 0) return -1;
		int pos = 0;
		for (int pw = 1 << 25; pw; pw >>= 1) {
			if (pos + pw <= sz(s) && s[pos + pw-1] < sum)
				pos += pw, sum -= s[pos-1];
		}
		return pos;
	}
};

const ll M = ll(1e17);
const int B = 18;

const ll INF = 2 * M;

const int NO = int(1e9);

struct Node {
	Node *l = 0, *r = 0;
	int lo, hi;
	ll madd = 0;
	ll val;
	// Node(int _lo,int _hi):lo(_lo),hi(_hi), val(INF){}
	Node(int _lo, int _hi, bool hello) : lo(_lo), hi(_hi) {
		val = INF;
		madd = 0;
		if (lo + 1 < hi) {
			int mid = lo + (hi - lo)/2;
			l = new Node(lo, mid, hello); r = new Node(mid, hi, hello);
		}
	}
	ll query(int L, int R) {
		if (R <= lo || hi <= L) return 2 * INF;
		if (L <= lo && hi <= R) return val;
		push();
		return min(l->query(L, R), r->query(L, R));
	}
	int leftmost(int L, int R, ll bound){
		if(R <= lo || hi <= L) return NO;
		if(L <= lo && hi <= R){
			if(val <= bound){
				if(lo + 1 == hi) return lo;
				push();
				int v = l->leftmost(L, R, bound);
				if(v != NO) return v;
				v = r->leftmost(L, R, bound);
				assert(v != NO);
				return v;
			} else {
				return NO;
			}
		} else {
			push();
			int v = l->leftmost(L, R, bound);
			if(v != NO) return v;
			v = r->leftmost(L, R, bound);
			return v;
		}
	}
	void add(int L, int R, ll x) {
		if (R <= lo || hi <= L) return;
		if (L <= lo && hi <= R) {
			madd += x;
			val += x;
		}
		else {
			push(), l->add(L, R, x), r->add(L, R, x);
			val = min(l->val, r->val);
		}
	}
	void push() {
		// if (!l) {
		// 	int mid = lo + (hi - lo)/2;
		// 	l = new Node(lo, mid); r = new Node(mid, hi);
		// }
		if (madd)
			l->add(lo,hi,madd), r->add(lo,hi,madd), madd = 0;
	}
};


int main(){
	ios_base::sync_with_stdio(false), cin.tie(nullptr);
	int n, q;
	cin >> n >> q;
	vector<ll> cnt0(n), wgt(n), val(n);
	vector<int> idx(n);
	vector<int> type(n);
	{
		vector<int> ord(n);
		vector<ll> _cnt(n), _wgt(n), _val(n);
		for(int i = 0; i < n; i++){
			cin >> _cnt[i] >> _wgt[i] >> _val[i];
			_val[i] = -_val[i];
		}
		for(int i = 0; i < n; i++) ord[i] = i;
		sort(ord.begin(), ord.end(), [&](int x, int y){
			return tie(_val[x], _wgt[x]) < tie(_val[y], _wgt[y]);
		});
		for(int i = 0; i < n; i++){
			cnt0[i] = _cnt[ord[i]];
			wgt[i] = _wgt[ord[i]];
			val[i] = -_val[ord[i]];
			idx[ord[i]] = i;
		}
	}
	for(int i = 0; i < n; i++){
		for(int b = 0; b < B; b++){
			if((1 << b) <= wgt[i]) type[i] = b;
		}
	}
	vector<ll> cnt(n, 0);
	vector<FT> val_ft(B, FT(n));
	vector<FT> wgt_ft(B, FT(n));
	vector<Node*> min_suff(B);
	for(int i = 0; i < B; i++){
		min_suff[i] = new Node(0, n, true);
	}
	auto upd = [&](int loc, ll del){
		for(int b = type[loc] + 1; b < B; b++){
			val_ft[b].update(loc, del * val[loc]);
			wgt_ft[b].update(loc, del * wgt[loc]);
		}
		for(int b = type[loc] + 1; b < B; b++){
			min_suff[b]->add(loc+1, n, del * wgt[loc]);
		}
		if((cnt[loc] == 0) && (cnt[loc] + del > 0)){
			min_suff[type[loc]]->add(loc, loc+1, wgt[loc] - INF);
		}
		if((cnt[loc] > 0) && (cnt[loc] + del == 0)){
			min_suff[type[loc]]->add(loc, loc+1, -(wgt[loc] - INF));
		}
		cnt[loc] += del;
	};
	for(int i = 0; i < n; i++){
		upd(i, cnt0[i]);
	}
	// cerr << "init ";
	// for(int i = 0; i < n; i++){
	// 	cerr << min_suff[2]->query(i, i+1) << ' ';
	// }
	// cerr << '\n';
	while(q--){
		int t;
		cin >> t;
		if(t == 1 || t == 2){
			ll k;
			int d;
			cin >> k >> d;
			d--;
			d = idx[d];
			if(t == 2) k = -k;
			upd(d, k);
			// for(int i = 0; i < n; i++){
			// 	cerr << cnt[i] << 'x' << wgt[i] << ' ' << val[i] << '\n';
			// }
		} else if(t == 3){
			ll c;
			cin >> c;
			ll ans = 0;
			int cur = 0;
			while(cur < n && c > 0){
				// cerr << "now " << cur << ' ' << c << '\n';
				int ctype = -1;
				for(int b = 0; b < B; b++){
					if((1 << b) <= c) ctype = b;
				}
				// cerr << "hi1" << '\n';
				ll pref_wgt_query = wgt_ft[ctype].query(cur);
				int lb = -1;
				if(ctype < (B-1)){
					int id = min_suff[ctype]->leftmost(cur, n, c + pref_wgt_query);
					if(id != NO){
						assert(id < n);
						assert(cnt[id] > 0);
						lb = id;
					}
				}
				// cerr << "hi2" << '\n';
				// cerr << lb << '\n';
				if(lb == -1){
					lb = wgt_ft[ctype].lower_bound(pref_wgt_query + c + 1);
				}
				c -= wgt_ft[ctype].query(lb) - pref_wgt_query;
				ans += val_ft[ctype].query(lb) - val_ft[ctype].query(cur);
				if(lb < n){
					assert(cnt[lb] > 0);
					ll take = min(cnt[lb], c / wgt[lb]);
					ans += take * val[lb];
					c -= take * wgt[lb];
					lb++;
				}
				cur = lb;
			}
			cout << ans << '\n';
		} else assert(false);
	}
}