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;
inline long long read() {
  long long x = 0, f = 1;
  char c = getchar();
  while (!isdigit(c)) {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (isdigit(c)) {
    x = (x << 3) + (x << 1) + (c ^ 48);
    c = getchar();
  }
  return f == 1 ? x : ~x + 1;
}
long long n, q;
struct item {
  long long w, v;
} a[200010];
long long cnt[200010];
const long long inf = 5e18;
struct BIT {
  long long siz;
  long long *tre1, *tre2;
  void init(long long x) {
    siz = x;
    tre1 = new long long[x + 10]();
    tre2 = new long long[x + 10]();
  }
  void upd(long long x, long long v, long long w) {
    while (x <= siz) {
      tre1[x] += v, tre2[x] += w;
      x += x & -x;
    }
  }
  long long queryv(long long x) {
    long long res = 0;
    while (x) {
      res += tre1[x];
      x -= x & -x;
    }
    return res;
  }
  long long queryw(long long x) {
    long long res = 0;
    while (x) {
      res += tre2[x];
      x -= x & -x;
    }
    return res;
  }
  long long bs(long long x) {
    long long res = 0;
    for (long long i = 20; i >= 0; --i) {
      if (siz >= (res | (1 << i))) {
        if (tre2[res | (1 << i)] <= x) {
          res |= (1 << i), x -= tre2[res];
        }
      }
    }
    return res;
  }
};
struct B {
  vector<long long> vec;
  long long siz;
  BIT T;
  long long id[200010];
  void build(long long up) {
    vec.clear();
    for (long long i = 1; i <= n; ++i) {
      if (a[i].w <= up) {
        vec.push_back(i);
      }
    }
    siz = vec.size();
    sort(vec.begin(), vec.end(), [&](long long x, long long y) {
      return a[x].v == a[y].v ? a[x].w < a[y].w : a[x].v > a[y].v;
    });
    for (long long i = 0; i < siz; ++i) {
      id[vec[i]] = i + 1;
    }
    T.init(siz);
    for (long long i : vec) {
      T.upd(id[i], 1ll * cnt[i] * a[i].v, 1ll * cnt[i] * a[i].w);
    }
  }
} st[21];
signed main() {
  n = read(), q = read();
  for (long long i = 1; i <= n; ++i)
    cnt[i] = read(), a[i].w = read(), a[i].v = read();
  for (long long i = 1; i <= 19; ++i) {
    st[i].build(1 << i - 1);
  }
  while (q--) {
    long long t = read();
    if (t == 1) {
      long long k = read(), d = read();
      cnt[d] += k;
      for (long long i = 1; i <= 19; ++i) {
        if (st[i].id[d]) {
          st[i].T.upd(st[i].id[d], 1ll * k * a[d].v, 1ll * k * a[d].w);
        }
      }
    } else if (t == 2) {
      long long k = read(), d = read();
      k = min(cnt[d], k);
      cnt[d] -= k;
      for (long long i = 1; i <= 19; ++i) {
        if (st[i].id[d]) {
          st[i].T.upd(st[i].id[d], -1ll * k * a[d].v, -1ll * k * a[d].w);
        }
      }
    } else {
      long long c = read(), ans = 0;
      long long maxv = 1e6;
      for (long long i = 19; i >= 1; --i) {
        long long l = 1, r = st[i].siz, res = r + 1;
        while (l <= r) {
          long long mid = l + r >> 1;
          if (a[st[i].vec[mid - 1]].v <= maxv)
            res = mid, r = mid - 1;
          else
            l = mid + 1;
        }
        if (res == st[i].siz + 1) continue;
        long long t = st[i].T.queryw(res - 1);
        long long R = st[i].T.bs(t + c);
        ans += st[i].T.queryv(R) - st[i].T.queryv(res - 1);
        c -= st[i].T.queryw(R) - t;
        ++R;
        if (R != st[i].siz + 1) {
          long long j = st[i].vec[R - 1];
          long long cnt = c / a[j].w;
          ans += cnt * a[j].v;
          c -= cnt * a[j].w;
          maxv = min(maxv, a[j].v);
        } else
          break;
      }
      printf("%lld\n", ans);
    }
  }
}
