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

#include <bits/stdc++.h>
#include <bits/extc++.h>

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;
typedef double db; 
typedef string str; 
 
typedef pair<int,int> pi;
typedef pair<ll,ll> pl; 
typedef pair<db,db> pd; 
 
typedef vector<int> vi; 
typedef vector<ll> vl; 
typedef vector<db> vd; 
typedef vector<str> vs; 
typedef vector<pi> vpi;
typedef vector<pl> vpl; 
typedef vector<pd> vpd;
typedef vector<vi> vvi; 

typedef set<int> si;

#define vt vector
#define mp make_pair
#define f first
#define s second
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define rall(x) (x).rbegin(), (x).rend() 
#define rsz resize
#define ins insert 
#define ft front() 
#define bk back()
#define pf push_front 
#define pb push_back
#define eb emplace_back 
#define lb lower_bound 
#define ub upper_bound
#define ts to_string
#define EACH(x, a) for (auto& x: a)

template<class T> void read(T &x){ cin >> x; }
template<class A> void read(vt<A> &v){ EACH(x, v) read(x); }
template<class H, class... T> void read(H& h, T& ...t){ read(h); read(t...); }

str to_string(const char* c){ return (str)c; }
str to_string(char c){ return (str)""+c; }
str to_string(str s){ return s; }
str to_string(bool b){ return b?"True" : "False"; }
template<class A> str to_string(vt<A> v){ str s; EACH(x, v) s+= to_string(x) + " "; return s; }
template<class H, class... T> str to_string(H& h, T& ...t){ str s; s+=to_string(h); s+=" "; s+=to_string(t...); return s; }
void print(str s){ cout << s << "\n"; }
template<class... A> void print(A ...a){ print(to_string(a...)); }


int cdiv(int a, int b) { return a/b+!(a<0||a%b == 0); }
str tb(int x) {str ans; int c = x; for(int i = log2(x); i >= 0; --i){if(pow(2,i) <= c){ ans += "1"; c-=pow(2,i); } else { ans += "0"; } } return ans;}
bool ispr(int x){if(x <= 1){return false;} for(int i = 2; i <= sqrt(x); ++i){ if(x%i == 0){ return false; } }return true; } 
			
const int MOD = 1e9+7; // 998244353;
const int MX = 2e5+5; 
const ll INF = 1e18;

//tree<int,null_type,less<int>, rb_tree_tag, tree_order_statistics_node_update> T;

vector<ll> BITval, BITwei;

int n, q;

struct shop{
	ll id, amount, weight, val;
};

vector<shop> v;

bool cmp(shop &a, shop &b){
	if(a.val != b.val)return a.val > b.val;
	if(a.weight != b.weight)return a.weight < b.weight;
	return a.id < b.id;
}

void add(int k, int d){
	int x = d;
	while(x <= n){
		BITval[x]+=v[d-1].val*k;
		BITwei[x]+=v[d-1].weight*k;
		x+=(x&(-x));
	}
}

pair<ll,ll> que(int x){
	pair<ll,ll> su = {0,0};
	while(x){
		su = {su.f+BITwei[x],su.s+BITval[x]};
		x-=(x&(-x));
	}
	return su;
}

ll fin(ll c){
	ll l = 1, r = n, bes = 0;
	while(l <= r){
		ll m = (l+r)>>1;
		pair<ll,ll> Q = que(m);
		if(Q.f > c)r = m-1;
		else{
			l = m+1, bes = m;
		}
	}
	pair<ll,ll> cu = que(bes);
	c-=cu.f;
	if(bes == n)return cu.s;
	return cu.s+(c/v[bes].weight)*v[bes].val;
}

void solve(){
	cin >> n >> q;
	BITval.resize(n+1,0);
	BITwei.resize(n+1,0);
	v.resize(n);
	for(int i = 0; i < n; ++i){
		cin >> v[i].amount >> v[i].weight >> v[i].val;
		v[i].id = i;
	}
	sort(all(v),cmp);
	
	vector<int> ids(n);
	for(int i = 0; i < n; ++i){
		ids[v[i].id] = i;
		add(v[i].amount,i+1);
	}
	while(q--){
		int t; cin >> t;
		if(t == 1){
			ll k, d; cin >> k >> d;
			v[ids[d-1]].amount+=k;
			add(k,ids[d-1]+1);
		}
		else if(t == 2){
			ll k, d; cin >> k >> d;
			v[ids[d-1]].amount-=k;
			add(-k,ids[d-1]+1);
		}
		else{
			ll c; cin >> c;
			cout << fin(c) << "\n";
		}
	}
}

int main(){
	std::ios::sync_with_stdio(0); std::cin.tie(0);
	
	bool isT = 0;
	if(isT){
		int t; cin >> t; while(t--){
			solve();
		}
		return 0;
	}
	solve();		
	return 0;
}
