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();
signed main() {
  home = 0;
  if (home) {
    freopen("tony_stark", "r", stdin);
  } else {
    ios::sync_with_stdio(0);
    cin.tie(0);
  }
  realMain();
}
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 K = 19;
int n, q, real_position[N], where[K][N];
T a[N];
vector<int> inds[N];
long long brute_force(long long c) {
  long long sol = 0;
  for (int i = 1; i <= n; 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;
  }
  return sol;
}
bool is_light(int k, int i) {
  assert(a[i].weight < (1 << k));
  return (a[i].weight < (1 << k) / 2);
}
bool is_heavy(int k, int i) { return !is_light(k, i); }
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;
}
long long rec(long long c, int pos, int k) {
  if (k < K - 1) {
    cout << " = " << k << "\n";
  }
  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;
  }
  while (ind < (int)inds[k].size() &&
         c - (long long)a[inds[k][ind]].cnt * a[inds[k][ind]].weight >=
             (1 << k)) {
    c -= (long long)a[inds[k][ind]].cnt * a[inds[k][ind]].weight;
    sol += (long long)a[inds[k][ind]].cnt * a[inds[k][ind]].value;
    ind++;
  }
  long long initc = c;
  if (ind < (int)inds[k].size()) {
    proc(c, sol, inds[k][ind]);
    ind++;
  }
  if (ind == (int)inds[k].size()) {
    return sol;
  }
  assert(c < (1 << k));
  while (c >= (1 << k) / 2) {
    if (ind == (int)inds[k].size()) {
      break;
    }
    proc(c, sol, inds[k][ind]);
    ind++;
  }
  if (ind == (int)inds[k].size()) {
    return sol;
  }
  assert(c < (1 << (k - 1)));
  return sol + rec(c, inds[k][pos], k - 1);
}
signed realMain() {
  cin >> n >> q;
  for (int i = 1; i <= n; i++) {
    cin >> a[i].cnt >> a[i].weight >> a[i].value;
    a[i].ind = i;
  }
  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;
  }
  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;
    }
    if (type == 2) {
      int k, d;
      cin >> k >> d;
      d = real_position[d];
      a[d].cnt -= k;
    }
    if (type == 3) {
      long long c;
      cin >> c;
      long long sol = rec(c, 1, K - 1);
      cout << sol << "\n";
    }
  }
  return 0;
}
