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 MN = 200005, P2 = (1 << 18), MTS = 2 * P2 + 5, inf = 1000000005,
          mod = 1000000007;
const long long INF = 1000000000000000005LL;
int wag[MN], val[MN], tmp[MN], V[MN], W[MN];
;
long long ile[MN];
int per[MN], gdzie[MN];
long long T[2][MTS];
bool comp(int x, int y) {
  return ((val[x] > val[y]) || (val[x] == val[y] && wag[x] < wag[y]));
}
void add(int id, int pos, long long val) {
  pos += P2;
  while (pos) {
    T[id][pos] += val;
    pos >>= 1;
  }
}
long long suma(int id, int a, int b) {
  a += P2, b += P2;
  long long ret = 0LL;
  while (a < b) {
    if (a & 1) ret += T[id][a++];
    if (!(b & 1)) ret += T[id][b--];
    a >>= 1, b >>= 1;
  }
  if (a == b) ret += T[id][a];
  return ret;
}
int bs(int zd, int zg, long long c) {
  while (zd != zg) {
    int mid = (zd + zg + 1) >> 1;
    if (suma(0, 1, mid) <= c)
      zd = mid;
    else
      zg = mid - 1;
  }
  return zd;
}
int main() {
  int n, q;
  scanf("%d%d", &n, &q);
  for (int i = 1; i <= n; ++i) {
    scanf("%d%d%d", &tmp[i], &wag[i], &val[i]);
    per[i] = i;
  }
  sort(per + 1, per + 1 + n, comp);
  for (int i = 1; i <= n; ++i) {
    ile[i] = tmp[per[i]];
    V[i] = val[per[i]];
    W[i] = wag[per[i]];
    gdzie[per[i]] = i;
    add(0, i, 1LL * ile[i] * W[i]);
    add(1, i, 1LL * ile[i] * V[i]);
  }
  for (int i = 1; i <= n; ++i) {
    val[i] = V[i];
    wag[i] = W[i];
  }
  while (q--) {
    int t;
    scanf("%d", &t);
    if (t < 3) {
      int znak = (t == 1) ? 1 : -1;
      int k, d;
      scanf("%d%d", &k, &d);
      d = gdzie[d];
      ile[d] += k * znak;
      add(0, d, 1LL * wag[d] * k * znak);
      add(1, d, 1LL * val[d] * k * znak);
    }
    if (t == 3) {
      long long c, ans;
      scanf("%lld", &c);
      int pos = bs(0, n, c);
      c -= suma(0, 1, pos);
      ans = suma(1, 1, pos);
      pos++;
      int cc = c;
      for (int i = pos; i <= n; ++i)
        if (wag[i] <= cc && ile[i] > 0LL) {
          int cnt = min((long long)cc, ile[i]);
          while (wag[i] <= cc && cnt) {
            ans += val[i];
            cc -= wag[i];
            --cnt;
          }
        }
      printf("%lld\n", ans);
    }
  }
}
