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>
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx")
using namespace std;
const auto start_time = std::chrono::high_resolution_clock::now();
void aryanc403() {}
const long long int INF = 0xFFFFFFFFFFFFFFFL;
long long int seed;
mt19937 rng(seed = chrono::steady_clock::now().time_since_epoch().count());
inline long long int rnd(long long int l = 0, long long int r = INF) {
  return uniform_int_distribution<long long int>(l, r)(rng);
}
class CMP {
 public:
  bool operator()(pair<long long int, long long int> a,
                  pair<long long int, long long int> b) {
    return !(a.first < b.first || (a.first == b.first && a.second <= b.second));
  }
};
void add(map<long long int, long long int> &m, long long int x,
         long long int cnt = 1) {
  auto jt = m.find(x);
  if (jt == m.end())
    m.insert({x, cnt});
  else
    jt->second += cnt;
}
void del(map<long long int, long long int> &m, long long int x,
         long long int cnt = 1) {
  auto jt = m.find(x);
  if (jt->second <= cnt)
    m.erase(jt);
  else
    jt->second -= cnt;
}
bool cmp(const pair<long long int, long long int> &a,
         const pair<long long int, long long int> &b) {
  return a.first < b.first || (a.first == b.first && a.second < b.second);
}
const long long int mod = 1000000007L;
const long long int logN = 22;
long long int ff(long long int x) {
  long long int i = 0;
  while ((1LL << i) <= x) i++;
  return i - 1;
}
struct ND {
  long long int mn;
  pair<long long int, long long int> cur, small;
  ND() : mn(INF), cur({0, 0}), small({0, 0}){};
  ND operator+(const ND &b) {
    ND ans;
    ans.mn = min(mn, b.mn);
    ans.cur.first = cur.first + b.cur.first;
    ans.cur.second = cur.second + b.cur.second;
    ans.small.first = small.first + b.small.first;
    ans.small.second = small.second + b.small.second;
    return ans;
  }
};
struct Node {
  long long int w, v, freq;
  int fl;
  array<ND, logN> a;
  Node() : w(INF), v(0), fl(0){};
  Node(long long int _w, long long int _v) : w(_w), v(_v), fl(ff(_w)){};
  Node operator+(const Node &b) {
    Node ans;
    for (int i = 0; i < logN; ++i) ans.a[i] = a[i] + b.a[i];
    return ans;
  }
  void increase(long long int f) {
    42;
    ;
    a[fl].cur.first += f * w;
    a[fl].cur.second += f * v;
    freq += f;
    42;
    ;
    if (freq)
      a[fl].mn = w;
    else
      a[fl].mn = INF;
    for (int i = fl + 1; i < logN; ++i) {
      a[i].small.first += f * w;
      a[i].small.second += f * v;
    }
  }
  int doesChange(long long int w) {
    const int gl = ff(w);
    if (gl >= logN) return 1;
    if (a[gl].mn <= w) return 0;
    if (a[gl].small.first >= w) return 0;
    if (a[gl].small.first < w) return 1;
    return -1;
  }
  pair<long long int, long long int> take(long long int w) {
    const int gl = min(ff(w), logN - 1);
    42;
    ;
    w -= a[gl].small.first;
    return {w, a[gl].small.second};
  }
  pair<long long int, long long int> takeCur(long long int ww) {
    long long int tt = min(freq, ww / w);
    return {ww - tt * w, tt * v};
  }
};
struct SegTree {
  vector<Node> a;
  int n;
  SegTree(int _n = 0) : a(4 * _n), n(_n){};
  void update(int id, int l, int r, int pos, long long int f) {
    if (pos < l || r < pos) return;
    if (l == r) {
      a[id].increase(f);
      return;
    }
    int m = (l + r) / 2;
    update(2 * id, l, m, pos, f);
    update(2 * id + 1, m + 1, r, pos, f);
    a[id] = Node();
    a[id] = a[id] + a[2 * id];
    a[id] = a[id] + a[2 * id + 1];
  }
  void update(int pos, long long int f) { return update(1, 0, n - 1, pos, f); }
  void build(vector<vector<long long int> > &aa, int id, int l, int r) {
    if (l == r) {
      a[id] = Node(aa[l][1], aa[l][2]);
      a[id].increase(aa[l][0]);
      return;
    }
    int m = (l + r) / 2;
    build(aa, 2 * id, l, m);
    build(aa, 2 * id + 1, m + 1, r);
    a[id] = a[2 * id] + a[2 * id + 1];
  }
  pair<long long int, long long int> run(int id, int l, int r,
                                         long long int w) {
    if (w == 0) return {0, 0};
    auto &cur = a[id];
    42;
    ;
    if (l == r) {
      42;
      ;
      return cur.takeCur(w);
    }
    const auto action = cur.doesChange(w);
    42;
    ;
    if (action) {
      if (action == 1) {
        42;
        ;
        return cur.take(w);
      }
      return {w, 0};
    }
    int m = (l + r) / 2;
    long long int val1 = 0, val2 = 0, w2;
    tie(w2, val1) = run(2 * id, l, m, w);
    w = w2;
    tie(w2, val2) = run(2 * id + 1, m + 1, r, w);
    return {w2, val1 + val2};
  }
  long long int run(long long int w) {
    auto ans = run(1, 0, n - 1, w);
    42;
    ;
    return ans.second;
  }
};
long long int T, n, i, j, k, in, cnt, l, r, u, v, x, y;
long long int m;
string s;
vector<long long int> a;
int main(void) {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  {
    long long int q;
    cin >> n >> q;
    vector<vector<long long int> > a(n, vector<long long int>(3));
    for (auto &v : a) cin >> v[0] >> v[1] >> v[2];
    vector<long long int> b(n);
    iota(begin(b), end(b), 0);
    sort(begin(b), end(b), [&](const long long int x, const long long int y) {
      if (a[x][2] != a[y][2]) return a[x][2] > a[y][2];
      return a[x][1] < a[y][1];
    });
    vector<long long int> id(n);
    for (int i = 0; i < n; ++i) id[b[i]] = i;
    sort(begin(a), end(a),
         [](const vector<long long int> &a, const vector<long long int> &b) {
           if (a[2] != b[2]) return a[2] > b[2];
           return a[1] < b[1];
         });
    42;
    ;
    SegTree seg(n);
    seg.build(a, 1, 0, n - 1);
    while (q--) {
      cin >> T;
      if (T == 3) {
        long long int w;
        cin >> w;
        cout << seg.run(w) << "\n";
        continue;
      }
      long long int k, d;
      cin >> k >> d;
      d = id[d - 1];
      if (T == 2) k *= -1;
      42;
      ;
      seg.update(d, k);
    }
  }
  aryanc403();
  return 0;
}
