#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
template<typename T>
void read(T &x){
	int ch = getchar(); x = 0; bool f = false;
	for(;ch < '0' || ch > '9';ch = getchar()) f |= ch == '-';
	for(;ch >= '0' && ch <= '9';ch = getchar()) x = x * 10 + ch - '0';
	if(f) x = -x;
} const int N = 200003, M = 1<<19, K = 18;
int n, q, w[N], v[N], id[N], pr[N], k;
LL a[N], w0[M][K], v0[M][K], w1[M][K], rem;
void pup(int x){
	int ls = x<<1, rs = x<<1|1;
	for(int i = 0;i < K;++ i){
		w0[x][i] = w0[ls][i] + w0[rs][i];
		v0[x][i] = v0[ls][i] + v0[rs][i];
		w1[x][i] = min(w1[ls][i], w0[ls][i] + w1[rs][i]);
	}
}
void upd(int x, int p){
	for(int i = 0;i < K;++ i){
		w0[x][i] = v0[x][i] = 0; w1[x][i] = 2e18;
		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 = 1, int L = 1, int R = n){
	if(L == R){upd(x, id[L]); return;}
	int mid = L+R>>1; build(x<<1, L, mid);
	build(x<<1|1, mid+1, R); pup(x);
}
void chan(int x = 1, int L = 1, int R = n){
	if(L == R){upd(x, id[L]); return;}
	int mid = L+R>>1;
	if(k <= mid) chan(x<<1, L, mid);
	else chan(x<<1|1, mid+1, R); pup(x);
} void upd(){while(k && rem < (1<<k)) -- k;}
LL query(int x = 1, int L = 1, int R = n){
	if(L == R){
		LL cnt = min(rem / w[id[L]], a[id[L]]);
		rem -= cnt * w[id[L]]; upd(); return cnt * v[id[L]];
	} if(rem >= w0[x][k+1]){rem -= w0[x][k+1]; LL tmp = v0[x][k+1]; upd(); return tmp;} // keng ?
	if(rem >= w0[x][k] && rem < w1[x][k]){rem -= w0[x][k]; LL tmp = v0[x][k]; upd(); return tmp;}
	int mid = L+R>>1; return query(x<<1, L, mid) + query(x<<1|1, mid+1, R);
}
int main(){
	read(n); read(q);
	for(int i = 1;i <= n;++ i){
		read(a[i]); read(w[i]); read(v[i]); id[i] = i;
	} sort(id + 1, id + n + 1, [&](int x, int y){return v[x] == v[y] && w[x] < w[y] || v[x] > v[y];});
	for(int i = 1;i <= n;++ i) pr[id[i]] = i; build();
	while(q --){
		int opt, y; read(opt);
		if(opt == 3){
			read(rem); k = 16; upd(); printf("%lld\n", query());
		} else {read(y); read(k); a[k] += (opt == 2 ? -y : y); k = pr[k]; chan();}
	}
}