2 8
2 15 400
1 13 100
3 26
3 27
3 28
3 29
3 30
3 31
3 32
3 33
 3 8
2 15 400
1 1 200
1 13 100
3 26
3 27
3 28
3 29
3 30
3 31
3 32
3 33

400
400
500
500
800
800
800
800
 600
600
600
700
800
1000
1000
1000

//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;
}