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;
int n, q;
const int maxN = 2e5 + 10;
long long a[maxN];
int w[maxN], cost[maxN];
int aa[maxN], ww[maxN], vv[maxN];
long long sumV[4 * maxN];
long long sumW[4 * maxN];
long long cnt[4 * maxN];
long long mn[4 * maxN];
void merge(int v) {
  sumV[v] = sumV[2 * v] + sumV[2 * v + 1];
  sumW[v] = sumW[2 * v] + sumW[2 * v + 1];
  cnt[v] = cnt[2 * v] + cnt[2 * v + 1];
  mn[v] = min(mn[2 * v], mn[2 * v + 1]);
}
void build(int v, int tl, int tr) {
  if (tl == tr) {
    sumV[v] = a[tl] * cost[tl];
    sumW[v] = a[tl] * w[tl];
    if (a[tl] > 0) {
      mn[v] = w[tl];
    } else {
      mn[v] = 2e18;
    }
    return;
  }
  int tm = (tl + tr) / 2;
  build(2 * v, tl, tm);
  build(2 * v + 1, tm + 1, tr);
}
int pos[maxN];
void upd(int v, int tl, int tr, int pos) {
  if (tl == tr) {
    sumV[v] = a[tl] * cost[tl];
    sumW[v] = a[tl] * w[tl];
    if (a[tl] > 0) {
      mn[v] = w[tl];
    } else {
      mn[v] = 2e18;
    }
    return;
  }
  int tm = (tl + tr) / 2;
  if (pos <= tm)
    upd(2 * v, tl, tm, pos);
  else
    upd(2 * v + 1, tm + 1, tr, pos);
  merge(v);
}
int find_lower(int v, int tl, int tr, int l, int r, long long c) {
  if (tr < l || r < tl) return -1;
  if (mn[v] > c) return -1;
  if (tl == tr) {
    return tl;
  }
  int tm = (tl + tr) / 2;
  int f = find_lower(2 * v, tl, tm, l, r, c);
  if (f != -1) return f;
  return find_lower(2 * v + 1, tm + 1, tr, l, r, c);
}
pair<int, bool> rec(int v, int tl, int tr, int st, long long& c,
                    long long& ans) {
  if (tr < st) return make_pair((tr + 1), true);
  if (st <= tl && sumW[v] <= c) {
    c -= sumW[v];
    ans += sumV[v];
    return make_pair(tr + 1, true);
  }
  if (tl == tr) {
    assert(sumW[v] > c);
    ans += (c / w[tl]) * cost[tl];
    c %= (w[tl]);
    return make_pair(tr + 1, false);
  }
  int tm = (tl + tr) / 2;
  auto pl = rec(2 * v, tl, tm, st, c, ans);
  if (pl.first != (tm + 1) || !pl.second) return pl;
  return rec(2 * v + 1, tm + 1, tr, st, c, ans);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> n >> q;
  vector<int> all(n);
  iota(all.begin(), all.end(), 1);
  for (int i = 1; i <= n; i++) {
    cin >> a[i] >> w[i] >> cost[i];
  }
  sort(all.begin(), all.end(), [&](int x, int y) {
    return make_pair(cost[x], -w[x]) > make_pair(cost[y], -w[y]);
  });
  for (int i = 1; i <= n; i++) {
    aa[i] = a[i];
    ww[i] = w[i];
    vv[i] = cost[i];
  }
  for (int i = 0; i < all.size(); i++) {
    pos[all[i]] = i + 1;
    a[i + 1] = aa[all[i]];
    cost[i + 1] = vv[all[i]];
    w[i + 1] = ww[all[i]];
  }
  build(1, 1, n);
  while (q--) {
    int tp;
    cin >> tp;
    if (tp == 1) {
      int k, d;
      cin >> k >> d;
      d = pos[d];
      a[d] += k;
      upd(1, 1, n, d);
    } else if (tp == 2) {
      int k, d;
      cin >> k >> d;
      d = pos[d];
      a[d] -= k;
      upd(1, 1, n, d);
    } else {
      long long c;
      cin >> c;
      long long ans = 0;
      int st = 1;
      while (c > 0 && st <= n) {
        int from = find_lower(1, 1, n, st, n, c);
        if (from == -1) break;
        st = from;
        st = rec(1, 1, n, st, c, ans).first;
      }
      cout << ans << '\n';
    }
  }
  return 0;
}
