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 inf = 1e18, nax = 2e5 + 10;
long long n, id[nax];
struct seg {
  long long w, v, t, a;
} d[nax];
struct node {
  long long sw[31], sv[31], ow[31], ov[31];
} st[800005];
void build(long long v, long long tl, long long tr, long long l, long long r) {
  if (l >= tr or r <= tl) return;
  if (tr - tl == 1) {
    for (long long k = 1; k <= 30; k++) {
      st[v].sw[k] = d[tl].a * d[tl].w * (d[tl].w < (1 << k));
      st[v].sv[k] = d[tl].a * d[tl].v * (d[tl].w < (1 << k));
      st[v].ow[k] = st[v].ov[k] = inf;
      if (d[tl].w >= (1 << (k - 1)) and d[tl].w < (1 << k) and d[tl].a > 0) {
        st[v].ow[k] = d[tl].w;
        st[v].ov[k] = d[tl].v;
      }
    }
  } else {
    long long md = (tl + tr) >> 1;
    build(2 * v + 1, tl, md, l, r);
    build(2 * v + 2, md, tr, l, r);
    for (long long k = 1; k <= 30; k++) {
      st[v].sw[k] = st[2 * v + 1].sw[k] + st[2 * v + 2].sw[k];
      st[v].sv[k] = st[2 * v + 1].sw[k] + st[2 * v + 2].sw[k];
      if (st[2 * v + 1].ow[k] < st[2 * v + 1].sw[k - 1] + st[2 * v + 2].ow[k]) {
        st[v].ow[k] = st[2 * v + 1].ow[k];
        st[v].ov[k] = st[2 * v + 1].ov[k];
      } else {
        st[2 * v + 1].ow[k] = st[2 * v + 1].sw[k - 1] + st[2 * v + 2].ow[k];
        st[2 * v + 1].ov[k] = st[2 * v + 1].ov[k - 1] + st[2 * v + 2].ov[k];
      }
    }
  }
}
void qry3(long long v, long long tl, long long tr, long long& pos, long long k,
          long long& c, long long& val) {
  if (pos == tr) return;
  if (pos == tl and st[v].sw[k] <= c) {
    c -= st[v].sw[k];
    val += st[v].sv[k];
    pos = tr;
  } else if (tr - tl > 1) {
    long long md = (tl + tr) >> 1;
    if (pos < md) qry3(2 * v + 1, tl, md, pos, k, c, val);
    if (pos >= md) qry3(2 * v + 2, md, tr, pos, k, c, val);
  }
}
array<long long, 2> qry2(long long v, long long tl, long long tr, long long l,
                         long long r, long long k) {
  if (l >= tr or r <= tl) return {inf, 0LL};
  if (tl >= l and tr <= r)
    return {st[v].ow[k], st[v].sw[k - 1]};
  else {
    long long md = (tl + tr) >> 1;
    array<long long, 2> low, high;
    low = qry2(2 * v + 1, tl, md, l, r, k);
    high = qry2(2 * v + 2, md, tr, l, r, k);
    if (low[0] < low[1] + high[0])
      return {low[0], low[1] + high[0]};
    else
      return {low[1] + high[0], low[1] + high[1]};
  }
}
array<long long, 4> qry4(long long v, long long tl, long long tr, long long l,
                         long long r, long long k) {
  if (l >= tr or r <= tl) return {inf, inf, 0, 0};
  if (tl >= l and tr <= r)
    return {st[v].ow[k], st[v].ov[k], st[v].sw[k - 1], st[v].sv[k - 1]};
  else {
    long long md = (tl + tr) >> 1;
    array<long long, 4> low, high;
    low = qry4(2 * v + 1, tl, md, l, r, k);
    high = qry4(2 * v + 2, md, tr, l, r, k);
    if (low[0] < low[2] + high[0])
      return {low[0], low[1], low[2] + high[2], low[3] + high[3]};
    else
      return {low[2] + high[0], low[3] + high[1], low[2] + high[2],
              low[3] + high[3]};
  }
}
long long qry1(long long v, long long tl, long long tr, long long& pos,
               long long k, long long& c) {
  if (pos == tr) return -1;
  if (pos == tl and st[v].ow[k] > c) {
    c -= st[v].sw[k - 1];
    pos = tr;
    return -1;
  } else if (tr - tl == 1) {
    c -= st[v].sw[k - 1];
    pos = tr;
    return tr;
  } else {
    long long md = (tl + tr) >> 1, res = -1;
    if (pos < md) res = qry1(2 * v + 1, tl, md, pos, k, c);
    if (res != -1) return res;
    if (pos >= md) res = qry1(2 * v + 2, md, tr, pos, k, c);
    return res;
  }
}
long long qry(long long pos, long long k, long long c) {
  return qry1(0, 0, n, pos, k, c);
}
void qq(long long& tl, long long k, long long& c, long long& val) {
  long long tr = qry(tl, k, c);
  if (tr != -1) {
    auto v = qry4(0, 0, n, tl, tr, k);
    tl = tr;
    c -= v[0];
    val += v[1];
  }
}
long long qry(long long c) {
  long long res = 0, pos = 0;
  for (long long i = 30; i >= 0; i--) {
    qry3(0, 0, n, pos, i, c, res);
    if (pos == n) break;
    long long val = min(d[pos].a, c / d[pos].w);
    c -= val * d[pos].w;
    res += val * d[pos].v;
    pos++;
    qq(pos, i, c, res);
  }
  return res;
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(nullptr);
  cin >> n;
  long long q;
  cin >> q;
  for (long long i = 0; i < n; i++) {
    cin >> d[i].a >> d[i].w >> d[i].v;
    d[i].t = i;
  }
  sort(d, d + n,
       [](seg x, seg y) { return (x.v != y.v) ? (x.v > y.v) : (x.w < y.w); });
  for (long long i = 0; i < n; i++) id[d[i].t] = i;
  build(0, 0, n, 0, n);
  while (q--) {
    long long type;
    cin >> type;
    if (type == 1) {
      long long pos, v;
      cin >> pos >> v;
      --v;
      d[id[v]].a += pos;
      build(0, 0, n, id[v], id[v] + 1);
    } else if (type == 2) {
      long long pos, v;
      cin >> pos >> v;
      --v;
      d[id[v]].a -= pos;
      build(0, 0, n, id[v], id[v] + 1);
    } else {
      long long x;
      cin >> x;
      cout << qry(x) << '\n';
    }
  }
  return 0;
}
