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

import java.util.Comparator;
import java.util.PriorityQueue;
import java.util.Scanner;

public class CI {
    private final static Scanner in = new Scanner(System.in);

    public static void main(String[] args) {
        int n = in.nextInt();
        int q = in.nextInt();
        diamond[] diamonds = new diamond[n];
        PriorityQueue<diamond> pq = new PriorityQueue<diamond>(n, new customComparator());
        for (int i = 0; i < n; i++) {
            int a = in.nextInt();
            int w = in.nextInt();
            int b = in.nextInt();
            diamonds[i] = new diamond(i, w, b, a);
            pq.add(diamonds[i]);
        }
        while (q-- != 0) {
            int t = in.nextInt();
            switch (t) {
                case 1:
                    int k = in.nextInt();
                    int d = in.nextInt() - 1;
                    diamond temp = new diamond(d, diamonds[d].wt, diamonds[d].val, diamonds[d].count + k);
                    pq.remove(diamonds[d]);
                    diamonds[d] = temp;
                    pq.add(diamonds[d]);
                    break;
                case 2:
                    int kk = in.nextInt();
                    int dd = in.nextInt() - 1;
                    diamond tempp = new diamond(dd, diamonds[dd].wt, diamonds[dd].val, diamonds[dd].count - kk);
                    pq.remove(diamonds[dd]);
                    diamonds[dd] = tempp;
                    pq.add(diamonds[dd]);
                    break;
                case 3:
                    long ci = in.nextLong();
                    compute(n,pq, ci);
                    break;

            }
        }
    }

    private static PriorityQueue<diamond> compute(int n,PriorityQueue<diamond> pq, long ci) {
        long currVal = 0;
        long currW = 0;
        // PriorityQueue<CI.diamond> p = new PriorityQueue<diamond>(n,new customComparator());

        // while(!pq.isEmpty()){
            // diamond d = pq.poll();
            // p.add(d);
            for(diamond d: pq){
            long maxVal = d.val*d.count;
            long maxW = d.wt*d.count;
            long req = ci- currW;
            if(maxW+currW<=ci){
                currVal+=maxVal;
                currW+=maxW;
            }else{
                long use = req/d.wt;
                currVal+=use*d.val;
                currW+=use*d.wt;
            }
        }
        System.out.println(currVal);
        return null;
    }

    static class diamond {
        int id;
        int wt;
        int val;
        int count;

        public diamond(int id, int wt, int val, int count) {
            this.id = id;
            this.wt = wt;
            this.val = val;
            this.count = count;
        }

    }

    static class customComparator implements Comparator<diamond> {

        public int compare(diamond d1, diamond d2) {
            if (d1.val < d2.val)
                return 1;
            else if (d1.val > d2.val)
                return -1;
            else {
                if (d1.wt > d2.wt)
                    return 1;
                if (d1.wt < d2.wt)
                    return -1;

            }
            return 0;
        }
    }
}
