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>
typedef long long i64;
#define sz(a) int((a).size())
#define all(a) (a).begin(), (a).end()
#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define per(i, a, b) for (int i = (b) - 1; i >= (a); --i)
using namespace std;

const int xn = 2e5, xk = 60;
int n, nq, o[xn];
struct jewel {i64 s; int w, v, i;} a[xn];
#define fk while (-1 != k and (1ll << k) > c) {--k;}

const int xns = xn * 2;
int ns, ls[xns], rs[xns]; 
i64 sw[xns][xk + 1], sv[xns][xk + 1], mn[xns][xk];
void pu(int u, int l = -1) {
  if (-1 != l) {
    i64 wi = a[l].s * a[l].w, vi = a[l].s * a[l].v;
    i64 c = a[l].w; int k = xk - 1; fk;
    rep(i, 0, xk + 1) {
      if (i > k) {sw[u][i] = wi; sv[u][i] = vi;}
      else {sw[u][i] = sv[u][i] = 0;}
    }
    rep(i, 0, xk) {mn[u][i] = 1ll << (i + 1);}
    if (a[l].s) {mn[u][k] = c;}
  } else {
    rep(i, 0, xk + 1) {
      sw[u][i] = sw[ls[u]][i] + sw[rs[u]][i];
      sv[u][i] = sv[ls[u]][i] + sv[rs[u]][i];
    }
    rep(i, 0, xk) {
      mn[u][i] = min(mn[ls[u]][i],
       sw[ls[u]][i] + mn[rs[u]][i]);
    }
  }
}
int nw(int l, int r) {
  int u = ns++; 
  if (r - l == 1) {pu(u, l); return u;}
  int mid = (l + r) / 2;
  ls[u] = nw(l, mid); rs[u] = nw(mid, r);
  pu(u); return u;
}
void mf(int x, int u, int l, int r) {
  if (r - l == 1) {pu(u, l); return;}
  int mid = (l + r) / 2;
  if (x < mid) {mf(x, ls[u], l, mid);}
  else {mf(x, rs[u], mid, r);}
  pu(u);
}
i64 c; int k;
i64 bs(int u, int l, int r) {
  if (-1 == k) {return 0ll;}
  if (r - l == 1) {
    i64 x = min(a[l].s, c / a[l].w);
    c -= x * a[l].w; fk;
    return x * a[l].v;
  }
  int mid = (l + r) / 2; i64 res = 0;
  if (c - sw[ls[u]][k] < (1ll << k) or
   mn[ls[u]][k] <= c) {res += bs(ls[u], l, mid);}
  else {c -= sw[ls[u]][k]; res += sv[ls[u]][k];}
  res += bs(rs[u], mid, r);
  return res;
}

int main() {
  ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  cin >> n >> nq;
  rep(i, 0, n) {
    cin >> a[i].s >> a[i].w >> a[i].v; a[i].i = i;
  }
  sort(a, a + n, [&](jewel &p, jewel &q) {
    return p.v != q.v ? p.v > q.v : p.w < q.w;
  });
  rep(i, 0, n) {o[a[i].i] = i;}
  int rt = nw(0, n); 
  rep(iq, 0, nq) {
    int t; cin >> t;
    if (t == 3) {
      cin >> c; k = xk - 1; fk;
      cout << bs(rt, 0, n) << '\n';
    } else {
      int k, i; cin >> k >> i; --i; i = o[i];
      t == 1 ? a[i].s += k : a[i].s -= k;
      mf(i, rt, 0, n);
    }
  }
  return 0;
}

/* 📌https://www.cnblogs.com/George1123/p/tips.html */