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>
const int Maxn = 200000;
const int Maxb = 9;
struct Node {
  int num, w, v, id;
  friend bool operator<(Node a, Node b) {
    if (a.v == b.v) {
      return a.w < b.w;
    }
    return a.v > b.v;
  }
} a[Maxn + 5];
int n, q;
int pos[Maxn + 5];
long long num[Maxn + 5];
int lis[Maxn + 5], rnk[Maxn + 5], val[Maxn + 5];
std::pair<long long, long long> sum[Maxn + 5];
int find_belong(int x) { return x >> Maxb; }
int find_bel_l(int x) { return x << Maxb; }
int find_bel_r(int x) { return std::min((x + 1) << Maxb, n); }
bool cmp_Node_w(int x, int y) { return a[x].w < a[y].w; }
void init_block(int id) {
  int bel_l = find_bel_l(id), bel_r = find_bel_r(id);
  for (int i = bel_l; i < bel_r; i++) {
    lis[i] = i;
  }
  std::sort(lis + bel_l, lis + bel_r, cmp_Node_w);
  long long sum_w = 0, sum_v = 0;
  for (int i = bel_l; i < bel_r; i++) {
    rnk[lis[i]] = i;
    val[i] = a[i].w;
    sum_w += a[i].w * num[i];
    sum_v += a[i].v * num[i];
    sum[i] = std::make_pair(sum_w, sum_v);
  }
}
std::pair<long long, long long> query(int id, long long v) {
  int bel_l = find_bel_l(id), bel_r = find_bel_r(id);
  return v < val[bel_l]
             ? std::make_pair(0ll, 0ll)
             : sum[std::upper_bound(val + bel_l, val + bel_r, v) - val - 1];
}
void init() {
  for (int i = 0; i <= find_belong(n); i++) {
    init_block(i);
  }
}
void update(int x, int v) {
  int id = find_belong(x);
  long long c_w = 1ll * a[x].w * v, c_v = 1ll * a[x].v * v;
  num[x] += v;
  for (int i = rnk[x]; i < find_bel_r(id); i++) {
    sum[i].first += c_w;
    sum[i].second += c_v;
  }
}
int main() {
  scanf("%d%d", &n, &q);
  for (int i = 0; i < n; i++) {
    scanf("%d%d%d", &a[i].num, &a[i].w, &a[i].v);
    a[i].id = i;
  }
  std::sort(a, a + n);
  for (int i = 0; i < n; i++) {
    pos[a[i].id] = i;
    num[i] = a[i].num;
  }
  init();
  for (int t = 1; t <= q; t++) {
    int op;
    scanf("%d", &op);
    if (op == 1 || op == 2) {
      op = (op == 1 ? 1 : -1);
      int x, v;
      scanf("%d%d", &v, &x);
      update(pos[x - 1], op * v);
    } else {
      long long w;
      scanf("%lld", &w);
      long long ans = 0;
      for (int j = 0; j <= find_belong(n); j++) {
        std::pair<long long, long long> tmp = query(j, w);
        if (tmp.first <= w) {
          w -= tmp.first;
          ans += tmp.second;
          continue;
        }
        for (int k = find_bel_l(j); k < find_bel_r(j); k++) {
          if (a[k].w <= w) {
            long long t_val = std::min(w / a[k].w, num[k]);
            w -= t_val * a[k].w;
            ans += t_val * a[k].v;
          }
        }
      }
      printf("%lld\n", ans);
    }
  }
  return 0;
}
