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 maxn=200005;
const int mlog=18;
const long long Inf=2e18;
int n,q,mx;
int w[maxn],r[maxn],v[maxn],p[maxn],ip[maxn];
long long a[maxn];

bool cmp(int x,int y){
	if(v[x]!=v[y])return v[x]>v[y];
	else return w[x]<w[y];
}

class Segtree1{
public:
	long long sumw[maxn*4],sumv[maxn*4];
	void update1(int cur,int l,int r,int k,long long val){
		if(l==r){
			sumw[cur]+=val*w[p[l]];
			sumv[cur]+=val*v[p[l]];
			return;
		}
		int mid=l+r>>1;
		if(k<=mid)update1(cur<<1,l,mid,k,val);
		else update1(cur<<1|1,mid+1,r,k,val);
		sumw[cur]=sumw[cur<<1]+sumw[cur<<1|1];
		sumv[cur]=sumv[cur<<1]+sumv[cur<<1|1];
	}
	long long query1(int cur,int l,int r,int vl,int vr){
		if(vl>vr)return 0;
		if(l>=vl&&r<=vr)return sumw[cur];
		int mid=l+r>>1;
		long long sl=mid>=vl?query1(cur<<1,l,mid,vl,vr):0;
		long long sr=mid<vr?query1(cur<<1|1,mid+1,r,vl,vr):0;
		return sl+sr;
	}
	int findp1(int cur,int l,int r,int vl,int vr,long long &val,long long &ans){
		if(l>=vl&&r<=vr&&sumw[cur]<=val){
			val-=sumw[cur];
			ans+=sumv[cur];
			return vr+1;
		}
		if(l==r)return l;
		int mid=l+r>>1;
		int res=mid>=vl?findp1(cur<<1,l,mid,vl,vr,val,ans):vr+1;
		if(res<=vr)return res;
		else return mid<vr?findp1(cur<<1|1,mid+1,r,vl,vr,val,ans):vr+1;
	}
}Tree1[mlog];

class Segtree2{
public:
	long long mn[maxn*4],tag[maxn*4];
	void update2(int cur,int l,int r,int vl,int vr,long long val){
		if(vl>vr)return;
		if(l>=vl&&r<=vr){
			mn[cur]+=val;
			tag[cur]+=val;
			return;
		}
		int mid=l+r>>1;
		if(mid>=vl)update2(cur<<1,l,mid,vl,vr,val);
		if(mid<vr)update2(cur<<1|1,mid+1,r,vl,vr,val);
		mn[cur]=min(mn[cur<<1],mn[cur<<1|1])+tag[cur];
	}
	void modify2(int cur,int l,int r,int k,long long val){
		if(l==r){
			mn[cur]=val;
			return;
		} 
		val-=tag[cur];
		int mid=l+r>>1;
		if(k<=mid)modify2(cur<<1,l,mid,k,val);
		else modify2(cur<<1|1,mid+1,r,k,val);
		mn[cur]=min(mn[cur<<1],mn[cur<<1|1])+tag[cur];
	}
	int findp2(int cur,int l,int r,int vl,int vr,long long val){
		if(l>=vl&&r<=vr&&mn[cur]>val)return vr+1;
		if(l==r)return l;
		val-=tag[cur];
		int mid=l+r>>1;
		int res=mid>=vl?findp2(cur<<1,l,mid,vl,vr,val):vr+1;
		if(res<=vr)return res;
		else return mid<vr?findp2(cur<<1|1,mid+1,r,vl,vr,val):vr+1;
	}
}Tree2[mlog];

void init(int i){
	for(int x=1;x<=n;x++)if(w[x]<(1<<i))
		Tree1[i].update1(1,1,n,ip[x],a[x]);
	for(int x=1;x<=n;x++){
		if(r[x]!=i||a[x]==0)Tree2[i].modify2(1,1,n,ip[x],Inf);
		else Tree2[i].modify2(1,1,n,ip[x],w[x]+Tree1[i].query1(1,1,n,1,ip[x]-1));
	}
}
void work(int x,long long b){
	for(int i=0;i<mlog;i++)if(w[x]<(1<<i)){
		Tree1[i].update1(1,1,n,ip[x],b);
		Tree2[i].update2(1,1,n,ip[x]+1,n,b*w[x]);
	}
	int j=r[x];
	if(!a[x])Tree2[j].modify2(1,1,n,ip[x],w[x]+Tree1[j].query1(1,1,n,1,ip[x]-1));
	a[x]+=b;
	if(!a[x])Tree2[j].modify2(1,1,n,ip[x],Inf);
}
long long answer(long long c){
	long long ans=0;
	int pt=1;
	for(int i=mlog-1;i>=0;i--)if(c>=(1<<i)){
		long long val=c-(1<<i);
		int rpt=Tree2[i].findp2(1,1,n,pt,n,c+Tree1[i].query1(1,1,n,1,pt-1));
		if(rpt>pt)pt=Tree1[i].findp1(1,1,n,pt,rpt-1,val,ans);
		c=(1<<i)+val;
		if(pt<=n){
			long long d=min(a[p[pt]],c/w[p[pt]]);
			c-=d*w[p[pt]];
			ans+=d*v[p[pt]];
			pt++;
		}
		if(pt>n)break;
		assert(c<(1<<i));
	}
	return ans;
}

int main(){
	scanf("%d%d",&n,&q);
	for(int i=1;i<=n;i++){
		scanf("%lld%d%d",&a[i],&w[i],&v[i]);
		p[i]=i;
		while(w[i]>=(1<<r[i]+1))r[i]++;
	}
	sort(p+1,p+1+n,cmp);
	for(int i=1;i<=n;i++)ip[p[i]]=i;
	for(int i=0;i<mlog;i++)init(i);
	while(q--){
		int op;
		scanf("%d",&op);
		if(op==1){
			int b,x;
			scanf("%d%d",&b,&x);
			work(x,b);
		}
		else if(op==2){
			int b,x;
			scanf("%d%d",&b,&x);
			work(x,-b);
		}
		else{
			long long c;
			scanf("%lld",&c);
			printf("%lld\n",answer(c));
		}
	}
	return 0;
}