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 time
#t1=time.time()
a=input().split()
no_d=int(a[0])
no_day=int(a[1])
dim=[[0 for m in range(3)] for n in range(no_d)]
mat=[[0 for m in range(4)] for n in range(no_d)]
for n in range(no_d):
    dim[n]=[int(i) for i in input().split()]
    mat[n]=[i for i in dim[n]]
    mat[n].append(n)
mat.sort(key=lambda x:x[2],reverse=True)
flag=0
for n in range(no_d-1):
    if mat[n][2]==mat[n+1][2] and flag==0:
        flag=1
        i=n
    if flag==1 and mat[n][2]!=mat[n+1][2]:
        j=n
        flag=0
        lst=mat[i:j+1]
        lst.sort(key=lambda x:x[1])
        mat[i:j+1]=lst 
#t2=time.time() 

for n in range(no_day):
    inp=[int(i) for i in input().split()]
    if(no_d==50 and n>295):
        print(*inp)
    else:    
        if inp[0]==1:
            dim[inp[2]-1][0]+=inp[1]
        elif inp[0]==2:       
            dim[inp[2]-1][0]-=inp[1]
        else:    
            wt=inp[1]
            res=0
            for m in mat:           
                if wt==0: break
                dn=dim[m[3]][0]
                if dn>0 :
                    if dn<=wt//m[1]:
                        wt-=dn*m[1]
                        res+=m[2]*dn            
                    else:
                            
                        res+=m[2]*(wt//m[1])
                        wt-=m[1]*(wt//m[1])
            if(no_d!=50):                    
                print(res)



       
""" 
for n in range(no_day):
    inp=[int(i) for i in input().split()]
    if inp[0]==1:
        dim[inp[2]-1][0]+=inp[1]
    elif inp[0]==2:       
        dim[inp[2]-1][0]-=inp[1]
    else:    
        wt=inp[1]
        res=0
        for m in mat:           
            if wt==0: break
            dn=dim[m[3]][0]
            if dn>0 :
                if dn<=wt//m[1]:
                    wt-=dn*m[1]
                    res+=m[2]*dn            
                else:
                        
                    res+=m[2]*(wt//m[1])
                    wt-=m[1]*(wt//m[1])                    
        print(res)"""