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

#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4.1,sse4.2,avx,avx2,popcnt,tune=native")
#include <bits/stdc++.h>

#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(),(x).end()

using namespace std;

typedef long long LL;
typedef pair<int,int> PII;
typedef vector < int > VI;
typedef double D;

const int MN = 200005, P2 = (1 << 18), MTS = 2 * P2 + 5, inf = 1000000005, mod = 1000000007;
const LL INF = 1000000000000000005LL;

int wag[MN], val[MN], tmp[MN], V[MN], W[MN];;
LL ile[MN];
int per[MN], gdzie[MN];

map < LL, LL > mapa;

LL T[2][MTS];

bool comp(int x, int y)
{
	return ((val[x] > val[y]) || (val[x] == val[y] && wag[x] < wag[y]));
}


void add(int id, int pos, LL val)
{
	pos += P2;
	while(pos)
	{
		T[id][pos] += val;
		pos >>= 1;
	}
}

LL suma(int id, int a, int b)
{
	a += P2, b += P2;
	LL ret = 0LL;
	while(a < b)
	{
		if(a & 1)
			ret += T[id][a++];
		if(!(b & 1))
			ret += T[id][b--];
		a >>= 1, b >>= 1;
	}
	if(a == b)
		ret += T[id][a];
	return ret;
}

int bs(int zd, int zg, LL c)
{
	while(zd != zg)
	{
		int mid = (zd + zg + 1) >> 1;
		if(suma(0, 1, mid) <= c)
			zd = mid;
		else
			zg = mid - 1;
	}
	return zd;
}

int main()
{
	int n, q;
	scanf("%d%d", &n, &q);
	for(int i = 1; i <= n; ++i)
	{
		scanf("%d%d%d", &tmp[i], &wag[i], &val[i]);
		per[i] = i;
	}
	sort(per + 1, per + 1 + n, comp);
	for(int i = 1; i <= n; ++i)
	{
		ile[i] = tmp[per[i]];
		V[i] = val[per[i]];
		W[i] = wag[per[i]];
		gdzie[per[i]] = i;
		add(0, i, 1LL * ile[i] * W[i]);
		add(1, i, 1LL * ile[i] * V[i]);
	}
	for(int i = 1; i <= n; ++i)
	{
		val[i] = V[i];
		wag[i] = W[i];
	}
	while(q--)
	{
		int t;
		scanf("%d", &t);
		if(t < 3)
		{
			int znak = (t == 1) ? 1 : -1;
			int k, d;
			scanf("%d%d", &k, &d);
			d = gdzie[d];
			ile[d] += 1LL * k * znak;
			add(0, d, 1LL * wag[d] * k * znak);
			add(1, d, 1LL * val[d] * k * znak);
			mapa.clear();
		}
		if(t == 3)
		{
			LL c;
			register long long ans;
			scanf("%lld", &c);
			if(mapa.find(c) != mapa.end())
			{
				printf("%lld\n", mapa[c]);
				continue;
			}
			LL xd = c;
			int pos = bs(0, n, c);
			c -= suma(0, 1, pos);
			ans = suma(1, 1, pos);
			pos++;
			if(ile[pos])
			{
				LL chce = min(ile[pos], c / (LL)wag[pos]);
				c -= chce * wag[pos];
				ans += chce * val[pos];
			}
			++pos;
			int cc = c;
			for(int i = pos; i <= n; ++i)
				if(wag[i] <= cc && ile[i])
				{
				    
					register int cnt = min((LL)cc, ile[i]);
					register int v = val[i], w = wag[i];
					while(w <= cc && cnt)
					{
						ans += v;
						cc -= w;
						--cnt;
					}
				}
			printf("%lld\n", ans);
			mapa[xd] = ans;
		}
	}
}
