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 xn = 2e5, xk = 60;
int n, nq, o[xn];
struct jewel {
  long long s;
  int w, v, i;
} a[xn];
const int xns = xn * 2;
int ns, ls[xns], rs[xns];
long long sw[xns][xk + 1], sv[xns][xk + 1], mn[xns][xk];
void pushup(int u, int l = -1) {
  if (-1 != l) {
    long long wi = a[l].s * a[l].w, vi = a[l].s * a[l].v;
    long long c = a[l].w;
    int k = xk - 1;
    while (-1 != k and (1ll << k) > c) {
      --k;
    }
    for (int i = (0); i < (xk + 1); ++i) {
      if (i > k) {
        sw[u][i] = wi;
        sv[u][i] = vi;
      } else {
        sw[u][i] = sv[u][i] = 0;
      }
    }
    for (int i = (0); i < (xk); ++i) {
      mn[u][i] = 1ll << (i + 1);
    }
    mn[u][k] = min(mn[u][k], c);
  } else {
    for (int i = (0); i < (xk + 1); ++i) {
      sw[u][i] = sw[ls[u]][i] + sw[rs[u]][i];
      sv[u][i] = sv[ls[u]][i] + sv[rs[u]][i];
      mn[u][i] = min(mn[ls[u]][i], mn[rs[u]][i] + sw[ls[u]][i]);
    }
  }
}
int nw(int l, int r) {
  int u = ns++;
  if (r - l == 1) {
    pushup(u, l);
    return u;
  }
  int mid = (l + r) / 2;
  ls[u] = nw(l, mid);
  rs[u] = nw(mid, r);
  pushup(u);
  return u;
}
void modify(int x, int u, int l, int r) {
  if (r - l == 1) {
    pushup(u, l);
    return;
  }
  int mid = (l + r) / 2;
  if (x < mid) {
    modify(x, ls[u], l, mid);
  } else {
    modify(x, rs[u], mid, r);
  }
  pushup(u);
}
long long c;
int k;
long long solve(int u, int l, int r) {
  if (-1 == k) {
    return 0ll;
  }
  if (r - l == 1) {
    long long x = min(a[l].s, c / a[l].w);
    c -= x * a[l].w;
    while (-1 != k and (1ll << k) > c) {
      --k;
    }
    return x * a[l].v;
  }
  int mid = (l + r) / 2;
  long long res = 0;
  if (c - sw[ls[u]][k] < (1ll << k) or mn[ls[u]][k] <= c) {
    res += solve(ls[u], l, mid);
  } else {
    c -= sw[ls[u]][k];
    res += sv[ls[u]][k];
  }
  res += solve(rs[u], mid, r);
  return res;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> nq;
  for (int i = (0); i < (n); ++i) {
    cin >> a[i].s >> a[i].w >> a[i].v;
    a[i].i = i;
  }
  sort(a, a + n,
       [&](jewel &p, jewel &q) { return p.v != q.v ? p.v > q.v : p.w < q.w; });
  for (int i = (0); i < (n); ++i) {
    o[a[i].i] = i;
  }
  int rt = nw(0, n);
  for (int iq = (0); iq < (nq); ++iq) {
    int t;
    cin >> t;
    if (t == 3) {
      cin >> c;
      k = xk - 1;
      while (-1 != k and (1ll << k) > c) {
        --k;
      }
      cout << solve(rt, 0, n) << '\n';
    } else {
      int k, i;
      cin >> k >> i;
      --i;
      i = o[i];
      t == 1 ? a[i].s += k : a[i].s -= k;
      modify(i, rt, 0, n);
    }
  }
  return 0;
}
