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 long long maxn = 200005, maxk = 19, maxt = maxn << 2;
long long n, m, omega, c;
long long pos[maxn], id[maxn], a[maxn], w[maxn], v[maxn], lc[maxt], rc[maxt],
    lightv[maxt][maxk], extra[maxt][maxk], lightw[maxt][maxk];
inline long long cmp(long long x, long long y) {
  return v[x] > v[y] || (v[x] == v[y] && w[x] < w[y]);
}
inline void getval(long long now, long long p) {
  for (long long i = 1; i <= 18; i++) {
    lightv[now][i] = lightw[now][i] = 0;
    if (w[p] < (1 << (i - 1)))
      lightv[now][i] = a[p] * v[p], lightw[now][i] = a[p] * w[p];
    else if (w[p] < (1 << i) && a[p] > 0)
      extra[now][i] = w[p];
  }
}
inline void pushup(long long now) {
  for (long long i = 1; i <= 18; i++) {
    lightv[now][i] = lightv[lc[now]][i] + lightv[rc[now]][i];
    lightw[now][i] = lightw[lc[now]][i] + lightw[rc[now]][i];
    extra[now][i] =
        min(extra[lc[now]][i], lightw[lc[now]][i] + extra[rc[now]][i]);
  }
}
void build(long long l, long long r, long long now) {
  if (l == r) {
    getval(now, id[l]);
    return;
  }
  long long mid = (l + r) >> 1;
  lc[now] = now << 1, rc[now] = now << 1 | 1;
  build(l, mid, lc[now]), build(mid + 1, r, rc[now]);
  pushup(now);
}
void update(long long l, long long r, long long now, long long pos) {
  if (l == r) {
    getval(now, id[l]);
    return;
  }
  long long mid = (l + r) >> 1;
  if (pos <= mid)
    update(l, mid, lc[now], pos);
  else
    update(mid + 1, r, rc[now], pos);
  pushup(now);
}
void calc() {
  while (omega > 1 && (1 << ((omega - 1) - 1)) > c) omega--;
}
long long query(long long l, long long r, long long now) {
  if (l == r) {
    long long num = min(a[id[l]], c / w[id[l]]);
    c -= num * w[id[l]], calc();
    return num * v[id[l]];
  }
  if (lightw[now][omega] <= c) {
    long long res = lightv[now][omega];
    c -= lightw[now][omega], calc();
    return res;
  }
  if (lightw[now][omega - 1] <= c && c < extra[now][omega - 1]) {
    long long res = lightv[now][omega - 1];
    c -= lightw[now][omega - 1], calc();
    return res;
  }
  long long mid = (l + r) >> 1;
  return query(l, mid, lc[now]) + query(mid + 1, r, rc[now]);
}
signed main() {
  scanf("%lld%lld", &n, &m);
  for (long long i = 1; i <= n; i++)
    scanf("%d%d%d", &a[i], &w[i], &v[i]), id[i] = i;
  sort(id + 1, id + 1 + n, cmp);
  for (long long i = 1; i <= n; i++) pos[id[i]] = i;
  build(1, n, 1);
  for (long long i = 1; i <= m; i++) {
    long long t, k, d;
    scanf("%d", &t);
    if (t == 1 || t == 2) {
      scanf("%d%d", &k, &d);
      a[d] += (t == 1 ? k : -k), update(1, n, 1, pos[d]);
    }
    if (t == 3) {
      scanf("%d", &c), omega = 18, calc();
      printf("%d\n", query(1, n, 1));
    }
  }
  return 0;
}
