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;
const int Inf = 0x3f3f3f3f;
const long long INF = 0x3f3f3f3f3f3f3f3fll;
const int maxn = 1 << 18, maxlg = 20;
struct Jew {
  int a, w, v, id;
  bool operator<(const Jew &x) const {
    return make_pair(-v, w) < make_pair(-x.v, w);
  }
} js[maxn];
pair<long long, long long> dt[maxlg + 1][maxn << 1];
long long mn[maxlg + 1][maxn << 1];
void inline add(int gr, int a, pair<int, int> x) {
  for (a += maxn; a; a >>= 1) {
    dt[gr][a].first += x.first;
    dt[gr][a].second += x.second;
  }
}
void inline change(int gr, int a, int x) {
  mn[gr][a += maxn] = x;
  while (a >>= 1) {
    mn[gr][a] = min(mn[gr][a << 1], mn[gr][a << 1 | 1]);
  }
}
int n, q;
int dy[maxn];
void inline solve(int now, int nl, int nr, long long &c, long long &ans) {
  if (nl >= n || !c) return;
  if (nl == nr) {
    long long sel = min<long long>(js[nl].a, c / js[nl].w);
    c -= sel * js[nl].w;
    ans += sel * js[nl].v;
    return;
  }
  int gr = min(maxlg, 63 - __builtin_clzll(c) + 1);
  bool cus = 1;
  if (dt[gr - 1][now].first > c) cus = 0;
  if (mn[gr][now] <= c && 2 * mn[gr][now] > c) cus = 0;
  if (cus) {
    c -= dt[gr - 1][now].first;
    ans += dt[gr - 1][now].second;
  } else {
    int m = (nl + nr) >> 1;
    solve(now << 1, nl, m, c, ans);
    solve(now << 1 | 1, m + 1, nr, c, ans);
  }
}
int main() {
  scanf("%d%d", &n, &q);
  for (int i = 0; i < (n); ++i)
    scanf("%d%d%d", &js[i].a, &js[i].w, &js[i].v), js[i].id = i + 1;
  sort(js, js + n);
  for (int i = 0; i < (n); ++i) dy[js[i].id] = i;
  memset(mn, Inf, sizeof(mn));
  for (int i = 0; i < (n); ++i) {
    for (int j = (min(maxlg, 63 - __builtin_clzll(js[i].w) + 1)); j <= (maxlg);
         ++j)
      add(j, i, make_pair(js[i].a * js[i].w, js[i].a * js[i].v));
    if (js[i].a)
      change(min(maxlg, 63 - __builtin_clzll(js[i].w) + 1), i, js[i].w);
  }
  while (q--) {
    int tp;
    scanf("%d", &tp);
    if (tp <= 2) {
      int k, d;
      scanf("%d%d", &k, &d);
      if (tp == 2) k *= -1;
      int i = dy[d];
      js[i].a += k;
      for (int j = (min(maxlg, 63 - __builtin_clzll(js[i].w) + 1));
           j <= (maxlg); ++j)
        add(j, i, make_pair(k * js[i].w, k * js[i].v));
      if (js[i].a)
        change(min(maxlg, 63 - __builtin_clzll(js[i].w) + 1), i, js[i].w);
      else
        change(min(maxlg, 63 - __builtin_clzll(js[i].w) + 1), i, Inf);
    } else {
      long long c, ans = 0;
      scanf("%lld", &c);
      solve(1, 0, maxn - 1, c, ans);
      printf("%lld\n", ans);
    }
  }
  return 0;
}
