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 M=62,N=1e5+7;
long long A,B,C,D,mx[M][N<<2],mn[M][N<<2],f1[M][N<<2],f2[M][N<<2];
int n,q,k,P,Q,L,G[N<<1],w[N<<1],s[N<<1],t[N<<1],pos[N<<1]; long long a[N<<1],f[N],g[N]; pair<long long,int>F[N];
struct node{
	int l,r; long long t;
}e;
vector<node>v[N<<1];
inline long long read(){
	long long num=0; char g=getchar(); while(g<48||57<g) g=getchar();
	while(47<g&&g<58) num=num*10+g-48,g=getchar(); return num;
}
inline void write(long long u){
	if(u>9) write(u/10); putchar(u%10+'0');
}
inline bool cmp(int a,int b){
	if(s[a]==s[b]) return w[a]>w[b]; return s[a]<s[b];
}
inline int logc(long long u){
	int p=0; while(u>0) u=u>>1,p++; return p;
}
inline void build(int l,int r,int t){
	mx[P][t]=mn[P][t]=-1; if(l==r) return;
	int d=(l+r)>>1; build(l,d,t<<1),build(d+1,r,t<<1|1); return;
}
inline void pushdown(int t){
	if(!f1[P][t]&&!f2[P][t]) return;
	if(mx[P][t<<1]!=-1){
		mx[P][t<<1]-=f1[P][t];
		mn[P][t<<1]-=f1[P][t];
		f1[P][t<<1]+=f1[P][t];
		f2[P][t<<1]+=f2[P][t];
	}
	if(mx[P][t<<1|1]!=-1){
		mx[P][t<<1|1]-=f1[P][t];
		mn[P][t<<1|1]-=f1[P][t];
		f1[P][t<<1|1]+=f1[P][t];
		f2[P][t<<1|1]+=f2[P][t];
	}
	f1[P][t]=0,f2[P][t]=0;
}
inline void add(int l,int r,int t){
	if(l==r){
		mx[P][t]=mn[P][t]=f[Q]; return;
	}
	pushdown(t);
	int d=(l+r)>>1;
	if(Q<=d) add(l,d,t<<1);
	else add(d+1,r,t<<1|1);
	if(mn[P][t<<1]==-1) mn[P][t]=mn[P][t<<1|1],mx[P][t]=mx[P][t<<1|1];
	else if(mn[P][t<<1|1]==-1) mn[P][t]=mn[P][t<<1],mx[P][t]=mx[P][t<<1];
	else mx[P][t]=max(mx[P][t<<1],mx[P][t<<1|1]),mn[P][t]=min(mn[P][t<<1],mn[P][t<<1|1]);
}
inline void upd(int l,int r,int t){
	if(l==r){
		if(mx[P][t]==-1) return;
		if(mx[P][t]<(1ll<<(P-1))){
			Q=l,g[Q]+=f2[P][t],L++,F[L]=make_pair(mx[P][t],l),mx[P][t]=-1,mn[P][t]=-1;
		}
		return;
	}
	pushdown(t);
	int d=(l+r)>>1;
	if(mn[P][t]>=(1ll<<(P-1))||mx[P][t]==-1) return;
	upd(l,d,t<<1),upd(d+1,r,t<<1|1);
	if(mn[P][t<<1]==-1) mn[P][t]=mn[P][t<<1|1],mx[P][t]=mx[P][t<<1|1];
	else if(mn[P][t<<1|1]==-1) mn[P][t]=mn[P][t<<1],mx[P][t]=mx[P][t<<1];
	else mx[P][t]=max(mx[P][t<<1],mx[P][t<<1|1]),mn[P][t]=min(mn[P][t<<1],mn[P][t<<1|1]);
}
inline void dfs(int l,int r,int t,int ql,int qr){
	if(l==r){
		if(mx[P][t]==-1) return;
		if(mx[P][t]>=B) mx[P][t]-=B,mn[P][t]-=B,f2[P][t]+=D;
		else f2[P][t]+=(mx[P][t]/A)*C,mx[P][t]%=A,mn[P][t]%=A;
		if(mx[P][t]<(1ll<<(P-1))){
			Q=l,g[Q]+=f2[P][t],L++,F[L]=make_pair(mx[P][t],l),mx[P][t]=-1,mn[P][t]=-1;
		}
		return;
	}
	if(l==ql&&r==qr){
		if(mn[P][t]>=B){
			f1[P][t]+=B,f2[P][t]+=D,pushdown(t);
			if(mn[P][t]<(1ll<<(P-1))) upd(l,r,t);
		}
		else if(mx[P][t]<A) pushdown(t);
		else{
			pushdown(t); int d=(l+r)>>1;
			dfs(l,d,t<<1,l,d),dfs(d+1,r,t<<1|1,d+1,r);
		}
		if(mn[P][t<<1]==-1) mn[P][t]=mn[P][t<<1|1],mx[P][t]=mx[P][t<<1|1];
		else if(mn[P][t<<1|1]==-1) mn[P][t]=mn[P][t<<1],mx[P][t]=mx[P][t<<1];
		else mx[P][t]=max(mx[P][t<<1],mx[P][t<<1|1]),mn[P][t]=min(mn[P][t<<1],mn[P][t<<1|1]);
		return;
	}
	int d=(l+r)>>1; pushdown(t);
	if(ql<=d) dfs(l,d,t<<1,ql,min(d,qr));
	if(d+1<=qr) dfs(d+1,r,t<<1|1,max(d+1,ql),qr);
	if(mn[P][t<<1]==-1) mn[P][t]=mn[P][t<<1|1],mx[P][t]=mx[P][t<<1|1];
	else if(mn[P][t<<1|1]==-1) mn[P][t]=mn[P][t<<1],mx[P][t]=mx[P][t<<1];
	else mx[P][t]=max(mx[P][t<<1],mx[P][t<<1|1]),mn[P][t]=min(mn[P][t<<1],mn[P][t<<1|1]);
}
inline void dfs2(int l,int r,int t){
	if(mx[P][t]==-1) return;
	if(l==r){
		g[l]+=f2[P][t]; return;
	}
	int d=(l+r)>>1;
	f2[P][t<<1]+=f2[P][t],f2[P][t<<1|1]+=f2[P][t];
	dfs2(l,d,t<<1),dfs2(d+1,r,t<<1|1);
}
int main(){
	cin>>n>>q; int op,c,d;
	for(int i=1;i<=n;i++) a[i]=read(),w[i]=read(),s[i]=read(),t[i]=1,G[i]=i;
	sort(G+1,G+n+1,cmp);
	for(int i=1;i<=q;i++){
		op=read();
		if(op==1){
			c=read(),d=read();
			e.l=t[d],e.r=k,e.t=a[d]; v[d].push_back(e),t[d]=k+1,a[d]+=c;
		}
		if(op==2){
			c=read(),d=read();
			e.l=t[d],e.r=k,e.t=a[d]; v[d].push_back(e),t[d]=k+1,a[d]-=c;
		}
		if(op==3){
			k++,f[k]=read();
		}
	}
	if(k==0) return 0;
	for(d=1;d<=n;d++) e.l=t[d],e.r=k,e.t=a[d],v[d].push_back(e);
	for(int i=0;i<=60;i++) P=i,build(1,k,1);
	for(int i=1;i<=k;i++) P=logc(f[i]),Q=i,add(1,k,1);
	for(int x=n;x>=1;x--){
		L=0; int i=G[x];
		for(int j=0;j<v[i].size();j++){
			if(v[i][j].t==0||v[i][j].l>v[i][j].r) continue;
			A=w[i],B=w[i]*v[i][j].t,C=s[i],D=s[i]*v[i][j].t;
			for(int w=0;w<=60;w++){
				P=w; if(mx[P][1]<A) continue; dfs(1,k,1,v[i][j].l,v[i][j].r);
			}
		}
		for(int j=1;j<=L;j++){
			f[F[j].second]=F[j].first,Q=F[j].second,P=logc(f[F[j].second]),add(1,k,1);
		}
	}
	for(int j=0;j<=60;j++) P=j,dfs2(1,k,1);
	for(int i=1;i<=k;i++) write(g[i]),putchar('\n');
}