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>
using namespace std;
std::mt19937 rnd(
    (int)std::chrono::steady_clock::now().time_since_epoch().count());
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
const int MAXN = 200000;
const int MAXQ = 100000;
const int MAXW = 100000;
const int MAXWLG = 17;
struct Diamond {
  int id, scnt, w, v;
};
int n, nq;
Diamond diamond[MAXN];
int qkind[MAXQ], qcnt[MAXQ], qtype[MAXQ];
long long qhave[MAXQ];
long long qans[MAXQ];
int pos[MAXN];
struct SegTree {
  int lim, n;
  vector<int> mp, fstmp;
  vector<int> id, w, v;
  vector<long long> cnt;
  vector<bool> issmall;
  vector<int> lastid;
  vector<long long> wsum, vsum, wsumsmall, vsumsmall, bestbig;
  void init(int _lim) {
    lim = _lim, n = 0;
    mp = vector<int>(::n, -1);
    id.clear(), w.clear(), v.clear(), cnt.clear(), issmall.clear();
    for (int i = (0); i < (::n); ++i)
      if (diamond[i].w <= lim) {
        mp[i] = n++;
        id.push_back(diamond[i].id);
        w.push_back(diamond[i].w);
        v.push_back(diamond[i].v);
        cnt.push_back(diamond[i].scnt);
        issmall.push_back(2 * diamond[i].w <= lim);
      }
    fstmp = mp;
    fstmp.push_back(n);
    for (int i = ::n - 1; i >= 0; --i)
      if (fstmp[i] == -1) fstmp[i] = fstmp[i + 1];
    lastid = vector<int>(4 * n);
    wsum = vsum = wsumsmall = vsumsmall = bestbig = vector<long long>(4 * n);
    if (n >= 1) init(0, 0, n - 1);
  }
  void init(int x, int l, int r) {
    if (l == r) {
      wsum[x] = (long long)cnt[l] * w[l];
      vsum[x] = (long long)cnt[l] * v[l];
      wsumsmall[x] = issmall[l] ? wsum[x] : 0;
      vsumsmall[x] = issmall[l] ? vsum[x] : 0;
      bestbig[x] = issmall[l] || cnt[l] == 0 ? LLONG_MAX : w[l];
    } else {
      int m = l + (r - l) / 2;
      init(2 * x + 1, l, m);
      init(2 * x + 2, m + 1, r);
      pull(x);
    }
  }
  void pull(int x) {
    wsum[x] = wsum[2 * x + 1] + wsum[2 * x + 2];
    vsum[x] = vsum[2 * x + 1] + vsum[2 * x + 2];
    wsumsmall[x] = wsumsmall[2 * x + 1] + wsumsmall[2 * x + 2];
    vsumsmall[x] = vsumsmall[2 * x + 1] + vsumsmall[2 * x + 2];
    bestbig[x] = bestbig[2 * x + 1];
    if (bestbig[2 * x + 2] != LLONG_MAX)
      bestbig[x] = min(bestbig[x], wsumsmall[2 * x + 1] + bestbig[2 * x + 2]);
  }
  void mod(int x, int l, int r, int IDX, int BY) {
    if (l == r) {
      wsum[x] += (long long)BY * w[l];
      vsum[x] += (long long)BY * v[l];
      if (issmall[l]) wsumsmall[x] += (long long)BY * w[l];
      if (issmall[l]) vsumsmall[x] += (long long)BY * v[l];
      cnt[l] += BY;
      bestbig[x] = issmall[l] || cnt[l] == 0 ? LLONG_MAX : w[l];
    } else {
      int m = l + (r - l) / 2;
      if (IDX <= m)
        mod(2 * x + 1, l, m, IDX, BY);
      else
        mod(2 * x + 2, m + 1, r, IDX, BY);
      pull(x);
    }
  }
  struct Res {
    int id;
    long long wsum, vsum;
    Res() {}
    Res(int id, long long wsum, long long vsum)
        : id(id), wsum(wsum), vsum(vsum) {}
  };
  Res findbig(int x, int l, int r, int L, int R, long long wlim) {
    if (L <= l && r <= R && bestbig[x] > wlim)
      return Res(-1, wsumsmall[x], vsumsmall[x]);
    if (l == r) return Res(id[x], wsum[x], vsum[x]);
    int m = l + (r - l) / 2;
    if (L <= m) {
      Res lres = findbig(2 * x + 1, l, m, L, R, wlim);
      if (lres.id != -1 || m + 1 > R) return lres;
      Res rres = findbig(2 * x + 2, m + 1, r, L, R, wlim - lres.wsum);
      return Res(rres.id, lres.wsum + rres.wsum, lres.vsum + rres.vsum);
    } else {
      return findbig(2 * x + 1, m + 1, r, L, R, wlim);
    }
  }
  Res findinterval(int x, int l, int r, int L, int R, long long wlim) {
    if (L <= l && r <= R && wsum[x] <= wlim) return Res(-1, wsum[x], vsum[x]);
    if (l == r) {
      long long t = wlim / w[l];
      assert(t < cnt[l]);
      return Res(id[l], t * w[l], t * v[l]);
    }
    int m = l + (r - l) / 2;
    if (L <= m) {
      Res lres = findinterval(2 * x + 1, l, m, L, R, wlim);
      if (lres.id != -1 || m + 1 > R) return lres;
      Res rres = findinterval(2 * x + 2, m + 1, r, L, R, wlim - lres.wsum);
      return Res(rres.id, lres.wsum + rres.wsum, lres.vsum + rres.vsum);
    } else {
      return findinterval(2 * x + 2, m + 1, r, L, R, wlim);
    }
  }
};
SegTree segtree[MAXWLG + 1];
void solve() {
  sort(diamond, diamond + n, [&](const Diamond &a, const Diamond &b) {
    if (a.v != b.v) return a.v > b.v;
    if (a.w != b.w) return a.w < b.w;
    return a.id < b.id;
  });
  for (int i = (0); i < (n); ++i) pos[diamond[i].id] = i;
  for (int k = (0); k <= (MAXWLG); ++k) segtree[k].init(1 << k);
  for (int i = (0); i < (nq); ++i) {
    if (qkind[i] == 1) {
      int idx = pos[qtype[i]];
      for (int k = (0); k <= (MAXWLG); ++k)
        if (segtree[k].mp[idx] != -1)
          segtree[k].mod(0, 0, segtree[k].n - 1, segtree[k].mp[idx], +qcnt[i]);
    }
    if (qkind[i] == 2) {
      int idx = pos[qtype[i]];
      for (int k = (0); k <= (MAXWLG); ++k)
        if (segtree[k].mp[idx] != -1)
          segtree[k].mod(0, 0, segtree[k].n - 1, segtree[k].mp[idx], -qcnt[i]);
    }
    if (qkind[i] == 3) {
      qans[i] = 0;
      int lastidx = -1;
      long long rem = qhave[i];
      for (int k = MAXWLG; k >= 0; --k) {
        int sidx = segtree[k].fstmp[lastidx + 1];
        if (sidx == segtree[k].n) continue;
        auto intres = segtree[k].findinterval(0, 0, segtree[k].n - 1, sidx,
                                              segtree[k].n - 1, rem);
        {
          lastidx = intres.id == -1 ? n - 1 : pos[intres.id] - 1;
          qans[i] += intres.vsum;
          rem -= intres.wsum;
        }
        sidx = segtree[k].fstmp[lastidx + 1];
        if (sidx == segtree[k].n) continue;
        assert(rem <= 1 << k);
        auto bigres = segtree[k].findbig(0, 0, segtree[k].n - 1, sidx,
                                         segtree[k].n - 1, rem);
        if (bigres.id != -1) {
          lastidx = pos[bigres.id];
          qans[i] += bigres.vsum;
          rem -= bigres.wsum;
        }
      }
    }
  }
}
void run() {
  scanf("%d%d", &n, &nq);
  for (int i = (0); i < (n); ++i)
    diamond[i].id = i,
    scanf("%d%d%d", &diamond[i].scnt, &diamond[i].w, &diamond[i].v);
  for (int i = (0); i < (nq); ++i) {
    scanf("%d", &qkind[i]);
    if (qkind[i] != 3)
      scanf("%d%d", &qcnt[i], &qtype[i]), --qtype[i];
    else
      scanf("%lld", &qhave[i]);
  }
  solve();
  for (int i = (0); i < (nq); ++i)
    if (qkind[i] == 3) printf("%lld\n", qans[i]);
}
int main() {
  run();
  return 0;
}
