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:
//CLOCKS_PER_SEC
using namespace std;
#include<bits/stdc++.h>
#define sqr(x) 1ll*(x)*(x)
//#define sort stable_sort
#define ll long long
#define mk make_pair
#define pb push_back
#define in insert
#define mtr(x,y,z) mk(mk(x,y),z)
#define fi first
#define se second
#define lch(x) ((x)<<1)
#define rch(x) (((x)<<1)|1)
#define all(x) (x).begin(),(x).end()
#define titose CLOCKS_PER_SEC
#define fpi(x) freopen(x,"r",stdin);
#define fpo(x) freopen(x,"w",stdout);
#define fprio fpi("in.txt");fpo("out.txt");
#define fast ios_base::sync_with_stdio(false);
inline void read(int &x){int v=0,f=1;char c=getchar();while (!isdigit(c)&&c!='-') c=getchar();if (c=='-') f=-1; else v=(c&15);while (isdigit(c=getchar())) v=(v<<1)+(v<<3)+(c&15);x=v*f;}
inline void read(ll &x){ll v=0ll,f=1ll;char c=getchar();while (!isdigit(c)&&c!='-') c=getchar();if (c=='-') f=-1; else v=(c&15);while (isdigit(c=getchar())) v=(v<<1)+(v<<3)+(c&15);x=v*f;}
inline void readc(char &x){char c;while (((c=getchar())==' ')||c=='\n');x=c;}
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vi vector<int>
#define vl vector<ll>
#define si set<int>
//#define sl set<ll>
#define mii map<int,int>
#define mll map<ll,ll>
#define msi map<string,int>
#define msl map<string,ll>
#define piii pair<int,pii >
#define piipi pair<pii,int>
#define plll pair<ll,pll >
#define pllpl pair<pll,ll>
#define pqi priority_queue<int>
#define pql priority_queue<ll>
#define npqi priority_queue<int,vector<int>,greater<int> >
#define npql priority_queue<ll,vector<ll>,greater<ll> >
#define forup(i,a,b) for ((i)=(a);(i)<=(b);(i)++)
#define fordo(i,a,b) for ((i)=(a);(i)>=(b);(i)--)
#define rep(i,x) forup ((i),1,(x))
#define repd(i,x) fordo ((i),(x),1)
#define rep0(i,x) forup ((i),0,((int)(x))-1)
#define rep0d(i,x) fordo ((i),((int)(x))-1,0)
#define itr iterator
#define fe(itcalc,c) for(__typeof((c).begin()) itcalc=(c).begin();itcalc!=(c).end();itcalc++)
#define NO {cout<<"NO";return 0;}
#define YES {cout<<"YES";return 0;}
#define y0 y000000000000000000000000000
#define y1 y111111111111111111111111111
#define j0 j000000000000000000000000000
#define j1 j111111111111111111111111111
#define cl0(a) memset((a),(0),(sizeof((a))))
#define clz(a) memset((a),(0x16),(sizeof((a))))
#define clf(a) memset((a),(-(0x16)),(sizeof((a))))
#define inf 0x3bbbbbbb
#define lnf 0x2bbbbbbbbbbbbbbbll
//#define sqrt divi
#define p2(i) (1ll<<(i))
#define readi read
#define readll read
/*************************************************/
int n,q,i,j,k,w[200005],v[200005],id[200005],mp[200005];
long long a[200005],rem;
long long w0[800005][19],v0[800005][19],w1[800005][19]; 
bool cmp(int x,int y)
{
	if(v[x]==v[y]) return w[x]<w[y];
	return v[x]>v[y];
}
void pushup(int x)
{
	int i;
	rep0(i,19){
		w0[x][i]=w0[x+x][i]+w0[x+x+1][i];
		v0[x][i]=v0[x+x][i]+v0[x+x+1][i];
		w1[x][i]=min(w1[x+x][i],w0[x+x][i]+w1[x+x+1][i]);
	}
}
void upd(int x,int p)
{
	int i;
	rep0(i,19){
		w0[x][i]=v0[x][i]=0;
		w1[x][i]=lnf;
		if(w[p]<(1<<i)){
			w0[x][i]=a[p]*w[p];
			v0[x][i]=a[p]*v[p];
		}
		else if(w[p]<(1<<(i+1))&&a[p]){
			w1[x][i]=w[p];
		}
	}
}
void build(int x,int l,int r)
{
	if(l==r){
		upd(x,id[l]);
		return;
	}
	int mid=(l+r)/2;
	build(x+x,l,mid);
	build(x+x+1,mid+1,r);
	pushup(x);
}
void update(int x,int l,int r)
{
	if(l==r){
		upd(x,id[l]);
		return; 
	}
	int mid=(l+r)/2;
	if(k<=mid) update(x+x,l,mid);
	else update(x+x+1,mid+1,r);
	pushup(x);
}
void f()
{
	while(k&&rem<(1<<k))k--;
}
long long query(int x,int l,int r)
{
	if(l==r){
		long long t=min(rem/w[id[l]],a[id[l]]);
		rem-=t*w[id[l]];
		f();
		return t*v[id[l]];
	}
	if(rem>=w0[x][k+1]){
		rem-=w0[x][k+1];
		long long tmp=v0[x][k+1];
		f();
		return tmp;
	}
	if(rem>=w0[x][k]&&rem<w1[x][k]){
		rem-=w0[x][k];
		long long tmp=v0[x][k];
		f();
		return tmp;
	}
	int mid=(l+r)/2;
	long long tt=query(x+x,l,mid);
	return tt+query(x+x+1,mid+1,r);
}
int main()
{
	read(n);read(q);
	rep(i,n){
		read(a[i]);read(w[i]);read(v[i]);
		id[i]=i;
	}
	sort(id+1,id+n+1,cmp);
	rep(i,n){
		mp[id[i]]=i;
	}
	build(1,1,n);
	while(q--){
		int op;
		read(op);
		if(op==3){
			read(rem);
			k=16;f();
			printf("%lld\n",query(1,1,n));
		}
		else{
			int x,y;
			read(x);read(y);
			if(op==1) a[y]+=x; else a[y]-=x;
			k=mp[y];
			update(1,1,n);
		}
	}
	return 0;
}