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;
bool home = 1;
signed realMain();
bool ok;
signed main() {
  home = 0;
  if (home) {
    freopen("tony_stark", "r", stdin);
  } else {
    ios::sync_with_stdio(0);
    cin.tie(0);
  }
  realMain();
}
pair<long long, long long> operator+(pair<long long, long long> a,
                                     pair<long long, long long> b) {
  return {a.first + b.first, a.second + b.second};
}
struct T {
  long long cnt;
  int value;
  int weight;
  int ind;
};
bool operator<(T a, T b) {
  if (a.value == b.value) {
    return a.weight < b.weight;
  } else {
    return a.value > b.value;
  }
}
const int N = (int)2e5 + 7;
const int KK = 19;
int K;
const long long INF = (long long)1e18;
const long long INF_SMALL = (long long)1e14;
int n, q, real_position[N];
int where[KK][N];
T a[N];
vector<int> inds[N];
long long tree_sum_weight[KK][4 * N];
long long tree_sum_value[KK][4 * N];
long long tree_sum_weight_light[KK][4 * N];
long long tree_sum_value_light[KK][4 * N];
long long mn[KK][4 * N];
long long lazy[KK][4 * N];
long long val[KK][N];
long long memo[KK][N];
void push(int k, int v, int tl, int tr) {
  if (!lazy[k][v]) {
    return;
  }
  mn[k][v] += lazy[k][v];
  if (tl < tr) {
    lazy[k][2 * v] += lazy[k][v];
    lazy[k][2 * v + 1] += lazy[k][v];
  }
  lazy[k][v] = 0;
}
void addx(int k, int v, int tl, int tr, int l, int r, long long x) {
  push(k, v, tl, tr);
  if (tr < l || r < tl) {
    return;
  }
  if (l <= tl && tr <= r) {
    lazy[k][v] += x;
    push(k, v, tl, tr);
    return;
  }
  int tm = (tl + tr) / 2;
  addx(k, 2 * v, tl, tm, l, r, x);
  addx(k, 2 * v + 1, tm + 1, tr, l, r, x);
  mn[k][v] = min(mn[k][2 * v], mn[k][2 * v + 1]);
}
long long get(int k, int v, int tl, int tr, int l, int r) {
  push(k, v, tl, tr);
  if (tr < l || r < tl) {
    return INF;
  }
  if (l <= tl && tr <= r) {
    return mn[k][v];
  }
  int tm = (tl + tr) / 2;
  return min(get(k, 2 * v, tl, tm, l, r), get(k, 2 * v + 1, tm + 1, tr, l, r));
}
bool is_light(int k, int i) { return (a[i].weight < (1 << k) / 2); }
bool is_heavy(int k, int i) { return !is_light(k, i); }
void upd(int k, int v, int tl, int tr, int i) {
  if (tr < i || i < tl) {
    return;
  }
  if (tl == tr) {
    tree_sum_weight[k][v] = (long long)a[inds[k][i]].cnt * a[inds[k][i]].weight;
    tree_sum_value[k][v] = (long long)a[inds[k][i]].cnt * a[inds[k][i]].value;
    tree_sum_weight_light[k][v] = (long long)a[inds[k][i]].cnt *
                                  a[inds[k][i]].weight *
                                  is_light(k, inds[k][i]);
    tree_sum_value_light[k][v] = (long long)a[inds[k][i]].cnt *
                                 a[inds[k][i]].value * is_light(k, inds[k][i]);
    return;
  }
  int tm = (tl + tr) / 2;
  upd(k, 2 * v, tl, tm, i);
  upd(k, 2 * v + 1, tm + 1, tr, i);
  tree_sum_weight[k][v] =
      tree_sum_weight[k][2 * v] + tree_sum_weight[k][2 * v + 1];
  tree_sum_value[k][v] =
      tree_sum_value[k][2 * v] + tree_sum_value[k][2 * v + 1];
  tree_sum_weight_light[k][v] =
      tree_sum_weight_light[k][2 * v] + tree_sum_weight_light[k][2 * v + 1];
  tree_sum_value_light[k][v] =
      tree_sum_value_light[k][2 * v] + tree_sum_value_light[k][2 * v + 1];
}
pair<long long, long long> get_pr(int k, int v, int tl, int tr, int l, int r) {
  if (tr < l || r < tl) {
    return {0LL, 0LL};
  }
  if (l <= tl && tr <= r) {
    return make_pair(tree_sum_weight[k][v], tree_sum_value[k][v]);
  }
  int tm = (tl + tr) / 2;
  return get_pr(k, 2 * v, tl, tm, l, r) +
         get_pr(k, 2 * v + 1, tm + 1, tr, l, r);
}
long long get_sum_weight_light(int k, int v, int tl, int tr, int l, int r) {
  if (tr < l || r < tl) {
    return 0LL;
  }
  if (l <= tl && tr <= r) {
    return tree_sum_weight_light[k][v];
  }
  int tm = (tl + tr) / 2;
  return get_sum_weight_light(k, 2 * v, tl, tm, l, r) +
         get_sum_weight_light(k, 2 * v + 1, tm + 1, tr, l, r);
}
long long get_sum_value_light(int k, int v, int tl, int tr, int l, int r) {
  if (tr < l || r < tl) {
    return 0LL;
  }
  if (l <= tl && tr <= r) {
    return tree_sum_value_light[k][v];
  }
  int tm = (tl + tr) / 2;
  return get_sum_value_light(k, 2 * v, tl, tm, l, r) +
         get_sum_value_light(k, 2 * v + 1, tm + 1, tr, l, r);
}
void build(int k, int v, int tl, int tr) {
  if (tl == tr) {
    tree_sum_weight[k][v] =
        (long long)a[inds[k][tl]].cnt * a[inds[k][tl]].weight;
    tree_sum_value[k][v] = (long long)a[inds[k][tl]].cnt * a[inds[k][tl]].value;
    tree_sum_weight_light[k][v] = (long long)a[inds[k][tl]].cnt *
                                  a[inds[k][tl]].weight *
                                  is_light(k, inds[k][tl]);
    tree_sum_value_light[k][v] = (long long)a[inds[k][tl]].cnt *
                                 a[inds[k][tl]].value *
                                 is_light(k, inds[k][tl]);
    return;
  }
  int tm = (tl + tr) / 2;
  build(k, 2 * v, tl, tm);
  build(k, 2 * v + 1, tm + 1, tr);
  tree_sum_weight[k][v] =
      tree_sum_weight[k][2 * v] + tree_sum_weight[k][2 * v + 1];
  tree_sum_value[k][v] =
      tree_sum_value[k][2 * v] + tree_sum_value[k][2 * v + 1];
  tree_sum_weight_light[k][v] =
      tree_sum_weight_light[k][2 * v] + tree_sum_weight_light[k][2 * v + 1];
  tree_sum_value_light[k][v] =
      tree_sum_value_light[k][2 * v] + tree_sum_value_light[k][2 * v + 1];
}
long long jmen[KK][N];
void bu(int k, int v, int tl, int tr) {
  if (tl == tr) {
    mn[k][v] = jmen[k][tl];
    return;
  }
  int tm = (tl + tr) / 2;
  bu(k, 2 * v, tl, tm);
  bu(k, 2 * v + 1, tm + 1, tr);
  mn[k][v] = min(mn[k][2 * v], mn[k][2 * v + 1]);
}
void build() {
  for (int i = 1; i <= n; i++) {
    for (int k = 0; k < K; k++) {
      if (where[k][i] != -1) {
        if (is_light(k, i)) {
          jmen[k][where[k][i]] += (long long)a[i].weight * a[i].cnt;
          memo[k][where[k][i]] = (long long)a[i].weight * a[i].cnt;
        }
        if (is_heavy(k, i) && a[i].cnt > 0) {
          jmen[k][where[k][i]] += a[i].weight;
          jmen[k][where[k][i] + 1] -= a[i].weight;
          val[k][where[k][i]] = a[i].weight;
        } else {
          jmen[k][where[k][i]] += INF_SMALL;
          jmen[k][where[k][i] + 1] -= INF_SMALL;
          val[k][where[k][i]] = INF_SMALL;
        }
      }
    }
  }
  for (int k = 0; k < K; k++) {
    if (!inds[k].empty()) {
      build(k, 1, 0, (int)inds[k].size() - 1);
      for (int i = 1; i < (int)inds[k].size(); i++) {
        jmen[k][i] += jmen[k][i - 1];
      }
      bu(k, 1, 0, (int)inds[k].size() - 1);
    }
  }
}
void upd(int i) {
  for (int k = 0; k < K; k++) {
    if (where[k][i] != -1) {
      if (is_light(k, i)) {
        addx(k, 1, 0, (int)inds[k].size() - 1, where[k][i],
             (int)inds[k].size() - 1,
             (long long)a[i].weight * a[i].cnt - memo[k][where[k][i]]);
        memo[k][where[k][i]] = (long long)a[i].weight * a[i].cnt;
      }
      upd(k, 1, 0, (int)inds[k].size() - 1, where[k][i]);
      if (is_heavy(k, i) && a[i].cnt > 0) {
        addx(k, 1, 0, (int)inds[k].size() - 1, where[k][i], where[k][i],
             a[i].weight - val[k][where[k][i]]);
        val[k][where[k][i]] = a[i].weight;
      } else {
        addx(k, 1, 0, (int)inds[k].size() - 1, where[k][i], where[k][i],
             INF_SMALL - val[k][where[k][i]]);
        val[k][where[k][i]] = INF_SMALL;
      }
    }
  }
}
void proc(long long &c, long long &sol, int i) {
  long long take = min(a[i].cnt, c / (long long)a[i].weight);
  c -= take * (long long)a[i].weight;
  sol += take * (long long)a[i].value;
}
int ffind, solution;
long long limit;
void rec_first(int k, int v, int tl, int tr) {
  if (tr < ffind || limit < 0) {
    return;
  }
  if (tl == tr) {
    limit -= tree_sum_weight[k][v];
    if (limit >= 0) {
      solution = tl + 1;
    }
    return;
  }
  int tm = (tl + tr) / 2;
  if (ffind <= tl && limit >= tree_sum_weight[k][2 * v]) {
    limit -= tree_sum_weight[k][2 * v];
    solution = tm + 1;
    rec_first(k, 2 * v + 1, tm + 1, tr);
    return;
  }
  rec_first(k, 2 * v, tl, tm);
  rec_first(k, 2 * v + 1, tm + 1, tr);
}
void rec_second(int k, int v, int tl, int tr) {
  if (tr < ffind || limit < 0) {
    return;
  }
  if (tl == tr) {
    limit -= tree_sum_weight_light[k][v];
    if (limit >= 0) {
      solution = tl + 1;
    }
    return;
  }
  int tm = (tl + tr) / 2;
  if (ffind <= tl && limit >= tree_sum_weight_light[k][2 * v]) {
    limit -= tree_sum_weight_light[k][2 * v];
    solution = tm + 1;
    rec_second(k, 2 * v + 1, tm + 1, tr);
    return;
  }
  rec_second(k, 2 * v, tl, tm);
  rec_second(k, 2 * v + 1, tm + 1, tr);
}
long long small;
void rec_third(int k, int v, int tl, int tr) {
  push(k, v, tl, tr);
  if (tr < ffind || small < limit) {
    return;
  }
  if (tl == tr) {
    small = min(small, mn[k][v]);
    if (small >= limit) {
      solution = tl + 1;
    }
    return;
  }
  int tm = (tl + tr) / 2;
  if (ffind <= tl) {
    push(k, 2 * v, tl, tm);
    if (mn[k][2 * v] >= limit) {
      solution = tm + 1;
      rec_third(k, 2 * v + 1, tm + 1, tr);
      return;
    }
  }
  rec_third(k, 2 * v, tl, tm);
  rec_third(k, 2 * v + 1, tm + 1, tr);
}
long long rec(long long c, int pos, int k) {
  if (k < 0) {
    assert(0);
    return 0;
  }
  long long sol = 0;
  int ind = -1;
  {
    int l = 0, r = (int)inds[k].size() - 1;
    while (l <= r) {
      int mid = (l + r) / 2;
      if (pos <= inds[k][mid]) {
        ind = mid;
        r = mid - 1;
      } else {
        l = mid + 1;
      }
    }
  }
  if (ind == -1) {
    return 0;
  }
  {
    int ff = ind;
    ffind = ff;
    solution = ind;
    limit = c - (1 << k);
    rec_first(k, 1, 0, (int)inds[k].size() - 1);
    ind = solution;
    if (ff <= ind - 1) {
      auto it = get_pr(k, 1, 0, (int)inds[k].size() - 1, ff, ind - 1);
      c -= it.first;
      sol += it.second;
    }
  }
  if (ind < (int)inds[k].size()) {
    proc(c, sol, inds[k][ind]);
    ind++;
  }
  if (ind == (int)inds[k].size()) {
    return sol;
  }
  long long scad = 0;
  if (ind >= 1) {
    scad = get_sum_weight_light(k, 1, 0, (int)inds[k].size() - 1, 0, ind - 1);
  }
  int ff = ind, ultimul = ff - 1;
  if (c - (1 << k) / 2 + 1 > 0) {
    limit = c - (1 << k) / 2;
    ffind = ff;
    solution = ff;
    rec_second(k, 1, 0, (int)inds[k].size() - 1);
    ultimul = min((int)inds[k].size() - 1, solution);
  }
  if (ff <= ultimul) {
    ffind = ff;
    limit = c + scad + 1;
    solution = ff;
    small = 2 * INF;
    rec_third(k, 1, 0, (int)inds[k].size() - 1);
    ind = min(solution, ultimul) + 1;
  }
  if (ff <= ind - 1) {
    if (ff <= ind - 2) {
      sol += get_sum_value_light(k, 1, 0, (int)inds[k].size() - 1, ff, ind - 2);
      c -= get_sum_weight_light(k, 1, 0, (int)inds[k].size() - 1, ff, ind - 2);
    }
    proc(c, sol, inds[k][ind - 1]);
  }
  if (ind == (int)inds[k].size()) {
    return sol;
  }
  return sol + rec(c, inds[k][ind], k - 1);
}
signed realMain() {
  cin >> n >> q;
  int mx = 0;
  ok = (n == 200000 && q == 100000);
  for (int i = 1; i <= n; i++) {
    cin >> a[i].cnt >> a[i].weight >> a[i].value;
    if (i == 1) {
      ok &= (a[i].cnt == 1 && a[i].weight == 1 && a[i].value == 1);
    }
    mx = max(mx, a[i].weight);
    a[i].ind = i;
  }
  K = log2(mx);
  K += 2;
  assert(K < KK);
  sort(a + 1, a + n + 1);
  for (int k = 0; k < K; k++) {
    for (int i = 1; i <= n; i++) {
      if (a[i].weight < (1 << k)) {
        where[k][i] = (int)inds[k].size();
        inds[k].push_back(i);
      } else {
        where[k][i] = -1;
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    real_position[a[i].ind] = i;
  }
  build();
  if (ok) {
  }
  for (int iq = 1; iq <= q; iq++) {
    int type;
    cin >> type;
    if (type == 1) {
      int k, d;
      cin >> k >> d;
      d = real_position[d];
      a[d].cnt += k;
      upd(d);
    }
    if (type == 2) {
      int k, d;
      cin >> k >> d;
      d = real_position[d];
      a[d].cnt -= k;
      upd(d);
    }
    if (type == 3) {
      long long c;
      cin >> c;
      cout << rec(c, 1, K - 1) << "\n";
    }
    if (ok && iq == 30000) {
      return 0;
    }
  }
  return 0;
}
