Problem: Phoenix wonders what it is like to rob diamonds from a jewelry store!

There are n types of diamonds. The i-th type has weight w_i and value v_i. The store initially has a_i diamonds of the i-th type.

Each day, for q days, one of the following will happen: 

  1. A new shipment of k_i diamonds of type d_i arrive. 
  2. The store sells k_i diamonds of type d_i. 
  3. Phoenix wonders what will happen if he robs the store using a bag that can fit diamonds with total weight not exceeding c_i. If he greedily takes diamonds of the largest value that fit, how much value would be taken? If there are multiple diamonds with the largest value, he will take the one with minimum weight. If, of the diamonds with the largest value, there are multiple with the same minimum weight, he will take any of them. 



Of course, since Phoenix is a law-abiding citizen, this is all a thought experiment and he never actually robs any diamonds from the store. This means that queries of type 3 do not affect the diamonds in the store.

Input

The first line contains two integers n and q (1 ≤ n ≤ 2 ⋅ 10^5; 1 ≤ q ≤ 10^5) — the number of types of diamonds and number of days, respectively.

The next n lines describe each type of diamond. The i-th line will contain three integers a_i, w_i, and v_i (0 ≤ a_i ≤ 10^5; 1 ≤ w_i, v_i ≤ 10^5) — the initial number of diamonds of the i-th type, the weight of diamonds of the i-th type, and the value of diamonds of the i-th type, respectively.

The next q lines contain the queries. For each query, the first integer of each line is t (1 ≤ t ≤ 3) — the type of query.

If t=1, then two integers k_i, d_i follow (1 ≤ k_i ≤ 10^5; 1 ≤ d_i ≤ n). This means that a new shipment of k_i diamonds arrived, each of type d_i.

If t=2, then two integers k_i, d_i follow (1 ≤ k_i ≤ 10^5; 1 ≤ d_i ≤ n). This means that the store has sold k_i diamonds, each of type d_i. It is guaranteed that the store had the diamonds before they sold them.

If t=3, an integer c_i will follow (1 ≤ c_i ≤ 10^{18}) — the weight capacity of Phoenix's bag.

It is guaranteed that there is at least one query where t=3.

Output

Print the answer for each query of the third type (t=3).

Example

Input


3 5
2 3 4
1 5 1
0 2 4
3 6
1 3 3
3 10
2 2 3
3 30


Output


8
16
13

Note

For the first query where t=3, Phoenix can fit 2 diamonds of type 1, with total weight 6 and value 8.

For the second query where t=3, Phoenix will first fit in 3 diamonds of type 3, then one diamond of type 1 for a total weight of 9 and a value of 16. Note that diamonds of type 3 are prioritized over type 1 because type 3 has equal value but less weight.

For the final query where t=3, Phoenix can fit every diamond for a total value of 13.

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
///#pragma GCC target("sse4.2")

///#pragma GCC opimize("O1")
///#pragma GCC opimize("O2")

///#pragma GCC opimize("Os")
///#pragma GCC opimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC target("avx2")



#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

using namespace std;

bool home = 1;
typedef long long ll;
typedef long double ld;
///#define int ll
signed realMain();

bool ok;

signed main() {
#ifdef ONLINE_JUDGE
  home = 0;
#endif
  if (home) {
    freopen ("tony_stark", "r", stdin);
  } else {
    ios::sync_with_stdio(0); cin.tie(0);
  }
  realMain();
}

pair<ll, ll> operator + (pair<ll, ll> a, pair<ll, ll> b) {
  return {a.first + b.first, a.second + b.second};
}

struct T {
  ll 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 KK = 19;
int K;
int sz[KK];
const ll INF = (ll) 1e18;
const ll INF_SMALL = (ll) 1e14;
int n, q, real_position[N];
int where[KK][N];
T a[N];
vector<int> inds[N];

ll aib_sum_weight[KK][N];
ll aib_sum_value[KK][N];
ll aib_sum_weight_light[KK][N];
ll aib_sum_value_light[KK][N];

ll mn[KK][4 * N];
ll lazy[KK][4 * N];
ll val[KK][N];
ll memo[KK][N];

void add_aib(ll aib[], int i, ll x, int sz) {
  if (!x) {
    return;
  }
  i++;
  while (i <= sz) {
    aib[i] += x;
    i += i & (-i);
  }
}

ll pre_aib(ll aib[], int i) {
  i++;
  ll sol = 0;
  while (i) {
    sol += aib[i];
    i -= i & (-i);
  }
  return sol;
}

void push(int k, int v, int tl, int tr) {
  if (!lazy[k][v]) {
    return;
  }
  mn[k][v] += lazy[k][v];
  if (tl < tr) {
    lazy[k][2 * v] += lazy[k][v];
    lazy[k][2 * v + 1] += lazy[k][v];
  }
  lazy[k][v] = 0;
}

void addx(int k, int v, int tl, int tr, int l, int r, ll x) {
  push(k, v, tl, tr);
  if (tr < l || r < tl) {
    return;
  }
  if (l <= tl && tr <= r) {
    lazy[k][v] += x;
    push(k, v, tl, tr);
    return;
  }
  int tm = (tl + tr) / 2;
  addx(k, 2 * v, tl, tm, l, r, x);
  addx(k, 2 * v + 1, tm + 1, tr, l, r, x);
  mn[k][v] = min(mn[k][2 * v], mn[k][2 * v + 1]);
}

ll get(int k, int v, int tl, int tr, int l, int r) {
  push(k, v, tl, tr);
  if (tr < l || r < tl) {
    return INF;
  }
  if (l <= tl && tr <= r) {
    return mn[k][v];
  }
  int tm = (tl + tr) / 2;
  return min(get(k, 2 * v, tl, tm, l, r), get(k, 2 * v + 1, tm + 1, tr, l, r));
}

bool is_light(int k, int i) {
  return (a[i].weight < (1 << k) / 2);
}

bool is_heavy(int k, int i) {
  return !is_light(k, i);
}

ll jmen[KK][N];

void bu(int k, int v, int tl, int tr) {
  if (tl == tr) {
    mn[k][v] = jmen[k][tl];
    return;
  }
  int tm = (tl + tr) / 2;
  bu(k, 2 * v, tl, tm);
  bu(k, 2 * v + 1, tm + 1, tr);
  mn[k][v] = min(mn[k][2 * v], mn[k][2 * v + 1]);
}

void build() {
  for (int i = 1; i <= n; i++) {
    for (int k = 0; k < K; k++) {
      if (where[k][i] != -1) {
        if (is_light(k, i)) {
          jmen[k][where[k][i]] += (ll) a[i].weight * a[i].cnt;
          memo[k][where[k][i]] = (ll) a[i].weight * a[i].cnt;
        }
        if (is_heavy(k, i) && a[i].cnt > 0) {
          jmen[k][where[k][i]] += a[i].weight;
          jmen[k][where[k][i] + 1] -= a[i].weight;
          val[k][where[k][i]] = a[i].weight;
        } else {
          jmen[k][where[k][i]] += INF_SMALL;
          jmen[k][where[k][i] + 1] -= INF_SMALL;
          val[k][where[k][i]] = INF_SMALL;
        }
      }
    }
  }
  for (int k = 0; k < K; k++) {
    if (!inds[k].empty()) {
      for (int i = 1; i < (int) inds[k].size(); i++) {
        jmen[k][i] += jmen[k][i - 1];
      }
      bu(k, 1, 0, (int) inds[k].size() - 1);
    }
  }
}

void upd(int i) {
  for (int k = 0; k < K; k++) {
    if (where[k][i] != -1) {
      if (is_light(k, i)) {
        addx(k, 1, 0, (int) inds[k].size() - 1, where[k][i], (int) inds[k].size() - 1, (ll) a[i].weight * a[i].cnt - memo[k][where[k][i]]);
        memo[k][where[k][i]] = (ll) a[i].weight * a[i].cnt;
      }
      if (is_heavy(k, i) && a[i].cnt > 0) {
        addx(k, 1, 0, (int) inds[k].size() - 1, where[k][i], where[k][i], a[i].weight - val[k][where[k][i]]);
        val[k][where[k][i]] = a[i].weight;
      } else {
        addx(k, 1, 0, (int) inds[k].size() - 1, where[k][i], where[k][i], INF_SMALL - val[k][where[k][i]]);
        val[k][where[k][i]] = INF_SMALL;
      }
    }
  }
}

void proc(ll &c, ll &sol, int i) {
  ll take = min(a[i].cnt, c / (ll) a[i].weight);
  c -= take * (ll) a[i].weight;
  sol += take * (ll) a[i].value;
}

int ffind, solution;
ll limit, small;

int steps;

void rec_third(int k, int v, int tl, int tr) {
  steps++;
  push(k, v, tl, tr);
  if (tr < ffind || small < limit) {
    return;
  }
  if (tl == tr) {
    small = min(small, mn[k][v]);
    if (small >= limit) {
      solution = tl + 1;
    }
    return;
  }
  int tm = (tl + tr) / 2;
  if (ffind <= tl) {
    push(k, 2 * v, tl, tm);
    if (mn[k][2 * v] >= limit) {
      solution = tm + 1;
      rec_third(k, 2 * v + 1, tm + 1, tr);
      return;
    }
  }
  rec_third(k, 2 * v, tl, tm);
  rec_third(k, 2 * v + 1, tm + 1, tr);
}

ll get_aib(ll aib[], int l, int r) {
  return pre_aib(aib, r) - pre_aib(aib, l - 1);
}

int go_bs;

ll rec(ll c, int pos, int k) {
  if (k < 0) {
    assert(0);
    return 0;
  }
  ll 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;
  }
  {
    int ff = ind, kek = -1;
    ll val = 0;
    if (ind >= 1) {
      val = pre_aib(aib_sum_weight[k], ind - 1);
    }
    val += c - (1 << k);
    if (val - c + (1 << k) + a[where[k][ind]].weight <= val) {
      for (int jump = go_bs; jump; jump /= 2) {
        if (kek + jump < (int) inds[k].size()) {
          if (aib_sum_weight[k][kek + jump + 1] <= val) {
            kek += jump;
            val -= aib_sum_weight[k][kek + 1];
          }
        }
      }
      ind = max(ind, kek + 1);
    }
    if (ff <= ind - 1) {
      int i = ind;
      while (i >= 1) {
        sol += aib_sum_value[k][i];
        c -= aib_sum_weight[k][i];
        i -= i & (-i);
      }
      i = ff;
      while (i >= 1) {
        sol -= aib_sum_value[k][i];
        c += aib_sum_weight[k][i];
        i -= i & (-i);
      }
    }
  }
  if (ind < (int) inds[k].size()) {
    proc(c, sol, inds[k][ind]);
    ind++;
  }
  if (ind == (int) inds[k].size()) {
    return sol;
  }
  ll scad = 0;
  if (ind >= 1) {
    scad = pre_aib(aib_sum_weight_light[k], ind - 1);
  }
  int ff = ind, ultimul = ff - 1;
  if (c - (1 << k) / 2 + 1 > 0) {

    int l = 0, r = (int) inds[k].size() - 1, kek = -1;
    ll val = c - (1 << k) / 2;
    if (ff - 1 >= 0) {
      val += pre_aib(aib_sum_weight_light[k], ff - 1);
    }
    for (int jump = go_bs; jump; jump /= 2) {
      if (kek + jump < (int) inds[k].size() && aib_sum_weight_light[k][kek + jump + 1] <= val) {
        kek += jump;
        val -= aib_sum_weight_light[k][kek + 1];
      }
    }
    ultimul = min((int) inds[k].size() - 1, kek + 1);
  }
  if (ff <= ultimul) {
    ffind = ff;
    limit = c + scad + 1;
    solution = ff;
    small = 2 * INF;
    rec_third(k, 1, 0, (int) inds[k].size() - 1);
    ind = min(solution, ultimul) + 1;
  }
  if (ff <= ind - 1) {
    if (ff <= ind - 2) {
      int i = ind - 1;
      while (i >= 1) {
        sol += aib_sum_value_light[k][i];
        c -= aib_sum_weight_light[k][i];
        i -= i & (-i);
      }
      i = ff;
      while (i >= 1) {
        sol -= aib_sum_value_light[k][i];
        c += aib_sum_weight_light[k][i];
        i -= i & (-i);
      }
    }
    proc(c, sol, inds[k][ind - 1]);
  }

  if (ind == (int) inds[k].size()) {
    return sol;
  }
  return sol + rec(c, inds[k][ind], k - 1);
}

signed realMain() {
  cin >> n >> q;
  go_bs = log2(n);
  go_bs = (1 << (go_bs + 1));
  assert(go_bs > n);
  int mx = 0;
  ok = (n == 200000 && q == 100000);
  for (int i = 1; i <= n; i++) {
    cin >> a[i].cnt >> a[i].weight >> a[i].value;
    if (i == 1) {
      ok &= (a[i].cnt == 1 && a[i].weight == 1 && a[i].value == 1);
    }
    mx = max(mx, a[i].weight);
    a[i].ind = i;
  }
  K = log2(mx);
  K += 2;
  assert(K < KK);
  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] = sz[k]++;
        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 k = 0; k < K; k++) {
      if (where[k][i] != -1) {
        add_aib(aib_sum_weight[k], where[k][i], (ll) a[i].cnt * a[i].weight, (int) inds[k].size());
        add_aib(aib_sum_value[k], where[k][i], (ll) a[i].cnt * a[i].value, (int) inds[k].size());
        add_aib(aib_sum_weight_light[k], where[k][i], (ll) a[i].cnt * a[i].weight * is_light(k, i), (int) inds[k].size());
        add_aib(aib_sum_value_light[k], where[k][i], (ll) a[i].cnt * a[i].value * is_light(k, i), (int) inds[k].size());
      }
    }
  }
  build();
  if (ok) {
    //return 0;
  }
  int mxs = 0;
  int c1 = 0, c2 = 0;
  for (int iq = 1; iq <= q; iq++) {
    int type;
    cin >> type;
    if (type == 1) {
      int grow, i;
      cin >> grow >> i;
      i = real_position[i];
      a[i].cnt += grow;
      for (int k = 0; k < K; k++) {
        if (where[k][i] != -1) {
          add_aib(aib_sum_weight[k], where[k][i], (ll) grow * a[i].weight, (int) inds[k].size());
          add_aib(aib_sum_value[k], where[k][i], (ll) grow * a[i].value, (int) inds[k].size());
          add_aib(aib_sum_weight_light[k], where[k][i], (ll) grow * a[i].weight * is_light(k, i), (int) inds[k].size());
          add_aib(aib_sum_value_light[k], where[k][i], (ll) grow * a[i].value * is_light(k, i), (int) inds[k].size());
        }
      }
      upd(i);
      c1++;
    }
    if (type == 2) {
      int take, i;
      cin >> take >> i;
      i = real_position[i];
      a[i].cnt -= take;
      for (int k = 0; k < K; k++) {
        if (where[k][i] != -1) {
          add_aib(aib_sum_weight[k], where[k][i], -(ll) take * a[i].weight, (int) inds[k].size());
          add_aib(aib_sum_value[k], where[k][i], -(ll) take * a[i].value, (int) inds[k].size());
          add_aib(aib_sum_weight_light[k], where[k][i], -(ll) take * a[i].weight * is_light(k, i), (int) inds[k].size());

          add_aib(aib_sum_value_light[k], where[k][i], -(ll) take * a[i].value * is_light(k, i), (int) inds[k].size());
        }
      }
      upd(i);
      c1++;
    }
    if (type == 3) {
      ll c;
      cin >> c;
      cout << rec(c, 1, K - 1) << "\n";
      c2++;
    }
    mxs = max(mxs, steps);
    steps = 0;
   /** if (ok && iq == 90000) {
      cout << "#" << c1 << "," << c2 << ":" << mxs << "\n";
      return 0;
    }**/
  }
  return 0;
}