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 ll = long long;
const int maxn = 2e5 + 5;
const int LIM = 17;
class Diamond {
 public:
  ll a;
  int w, v, id;
  Diamond(ll _a = 0, int _w = 0, int _v = 0, int _id = 0)
      : a(_a), w(_w), v(_v), id(_id) {}
  bool operator<(const Diamond &rhs) const {
    if (v != rhs.v) return v > rhs.v;
    return w < rhs.w;
  }
};
class Seg {
 public:
  int k;
  class Node {
   public:
    ll sumw, sumv;
    int w, v;
    int one_w;
    Node(ll _sumw = 0, ll _sumv = 0, int _w = 0x3f3f3f3f, int _v = 0,
         int _one_w = 0x3f3f3f3f)
        : sumw(_sumw), sumv(_sumv), w(_w), v(_v), one_w(_one_w) {}
  } t[maxn * 4];
  void pushup(int p) {
    t[p].sumw = t[(p << 1)].sumw + t[(p << 1 | 1)].sumw;
    t[p].sumv = t[(p << 1)].sumv + t[(p << 1 | 1)].sumv;
    t[p].one_w = std::min(t[(p << 1)].one_w, t[(p << 1 | 1)].one_w);
    t[p].w = std::min(t[(p << 1)].w, t[(p << 1 | 1)].w);
  }
  void build(int l, int r, int p, const std::vector<Diamond> &dia) {
    if (l + 1 == r) {
      if (dia[l].w < (1 << k)) {
        t[p] = Node(1ll * dia[l].w * dia[l].a, 1ll * dia[l].v * dia[l].a,
                    dia[l].w, dia[l].v);
      } else if (dia[l].a > 0 && dia[l].w >= (1 << k) &&
                 dia[l].w < (1 << (k + 1))) {
        t[p] = Node(0, 0, 0, 0, dia[l].w);
      }
      return;
    }
    build(l, ((l + r - 1) / 2) + 1, (p << 1), dia);
    build(((l + r - 1) / 2) + 1, r, (p << 1 | 1), dia);
    pushup(p);
  }
  void modify(int l, int r, int p, int pos, const std::vector<Diamond> &dia) {
    if (l + 1 == r) {
      if (dia[l].w < (1 << k)) {
        t[p] = Node(1ll * dia[l].w * dia[l].a, 1ll * dia[l].v * dia[l].a,
                    dia[l].w, dia[l].v);
      } else if (dia[l].a > 0 && dia[l].w >= (1 << k) &&
                 dia[l].w < (1 << (k + 1))) {
        t[p] = Node(0, 0, 0, 0, dia[l].w);
      }
      return;
    }
    if (pos <= ((l + r - 1) / 2))
      modify(l, ((l + r - 1) / 2) + 1, (p << 1), pos, dia);
    else
      modify(((l + r - 1) / 2) + 1, r, (p << 1 | 1), pos, dia);
    pushup(p);
  }
  std::pair<ll, std::pair<ll, int>> query(int l, int r, int ql, int qr, int p,
                                          ll V) {
    if (ql >= qr) return std::make_pair(0, std::make_pair(V, ql));
    if (ql <= l && qr >= r) {
      if (t[p].sumw <= V)
        return std::make_pair(t[p].sumv, std::make_pair(V - t[p].sumw, r));
      if (l + 1 == r) {
        if (t[p].sumw <= V)
          return std::make_pair(t[p].sumv, std::make_pair(V - t[p].sumw, r));
        return std::make_pair(V / t[p].w * t[p].v,
                              std::make_pair(V % t[p].w, r));
      }
      if (V > t[(p << 1)].sumw) {
        std::pair<ll, std::pair<ll, int>> rnt =
            query(((l + r - 1) / 2) + 1, r, ((l + r - 1) / 2) + 1, r,
                  (p << 1 | 1), V - t[(p << 1)].sumw);
        rnt.first += t[(p << 1)].sumv;
        return rnt;
      } else
        return query(l, ((l + r - 1) / 2) + 1, l, ((l + r - 1) / 2) + 1,
                     (p << 1), V);
    }
    if (qr <= ((l + r - 1) / 2) + 1)
      return query(l, ((l + r - 1) / 2) + 1, ql, qr, (p << 1), V);
    else if (ql > ((l + r - 1) / 2))
      return query(((l + r - 1) / 2) + 1, r, ql, qr, (p << 1 | 1), V);
    else {
      std::pair<ll, std::pair<ll, int>> L = query(
          l, ((l + r - 1) / 2) + 1, ql, ((l + r - 1) / 2) + 1, (p << 1), V);
      if (L.second.second <= ((l + r - 1) / 2)) return L;
      std::pair<ll, std::pair<ll, int>> R =
          query(((l + r - 1) / 2) + 1, r, ((l + r - 1) / 2) + 1, qr,
                (p << 1 | 1), L.second.first);
      if (R.first > 0) {
        R.first += L.first;
        return R;
      } else
        return L;
    }
  }
  int query_one_pos(int l, int r, int ql, int qr, int p, ll V) {
    if (ql >= qr) return r;
    if (t[p].one_w > V) return r;
    if (ql <= l && qr >= r) {
      if (l + 1 == r) return l;
      if (t[(p << 1)].one_w <= V)
        return query_one_pos(l, ((l + r - 1) / 2) + 1, l, ((l + r - 1) / 2) + 1,
                             (p << 1), V);
      else
        return query_one_pos(((l + r - 1) / 2) + 1, r, ((l + r - 1) / 2) + 1, r,
                             (p << 1 | 1), V);
    }
    if (qr <= ((l + r - 1) / 2) + 1)
      return query_one_pos(l, ((l + r - 1) / 2) + 1, ql, qr, (p << 1), V);
    else if (ql > ((l + r - 1) / 2))
      return query_one_pos(((l + r - 1) / 2) + 1, r, ql, qr, (p << 1 | 1), V);
    else {
      int L = query_one_pos(l, ((l + r - 1) / 2) + 1, ql, ((l + r - 1) / 2) + 1,
                            (p << 1), V);
      if (L < ((l + r - 1) / 2) + 1) return L;
      int R = query_one_pos(((l + r - 1) / 2) + 1, r, ((l + r - 1) / 2) + 1, qr,
                            (p << 1 | 1), V);
      return R;
    }
  }
} SEG[20];
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  int n, q;
  std::cin >> n >> q;
  std::vector<Diamond> dia(n);
  for (int i = 0; i < n; i++) {
    int a, w, v;
    std::cin >> a >> w >> v;
    dia[i] = Diamond(a, w, v, i);
  }
  std::sort(dia.begin(), dia.end());
  std::vector<int> id(n);
  for (int i = 0; i < n; i++) {
    id[dia[i].id] = i;
  }
  for (int i = 1; i <= LIM; i++) SEG[i].k = i;
  for (int i = 1; i <= LIM; i++) SEG[i].build(0, n, 1, dia);
  while (q--) {
    int type, k, d;
    std::cin >> type;
    if (type == 1) {
      std::cin >> k >> d;
      d--;
      dia[id[d]].a += k;
      for (int i = 1; i <= LIM; i++) {
        SEG[i].modify(0, n, 1, id[d], dia);
      }
    } else if (type == 2) {
      std::cin >> k >> d;
      d--;
      dia[id[d]].a -= k;
      for (int i = 1; i <= LIM; i++) {
        SEG[i].modify(0, n, 1, id[d], dia);
      }
    } else {
      ll c, ans = 0;
      int l = 0, r = 0;
      std::cin >> c;
      std::pair<ll, std::pair<ll, int>> init = SEG[LIM].query(0, n, 0, n, 1, c);
      c = init.second.first;
      l = init.second.second;
      ans = init.first;
      assert(c < (1 << LIM) || l >= n);
      for (int i = LIM; i >= 1; i--) {
        if (l >= n) break;
        r = SEG[i].query_one_pos(0, n, l, n, 1, c);
        if (l < r) {
          init = SEG[i].query(0, n, l, r, 1, c);
          c = init.second.first;
          l = init.second.second;
          ans += init.first;
        }
        if (r < n) {
          if (c >= dia[id[r]].w && dia[id[r]].a > 0) {
            c -= dia[id[r]].w;
            ans += dia[id[r]].w;
            l = r + 1;
          }
        }
      }
      std::cout << ans << std::endl;
    }
  }
  return 0;
}
