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 sys
input = sys.stdin.readline

# Input
def inI():
    inputLine = input().split()
    return int(inputLine[0]) if len(inputLine) == 1 else map(int, inputLine)

def inIL():
    return list(map(int, input().split()))

def inCL():
    return list(input())[:-1]

# Output
def out(*liste):
    if isinstance(liste[0], list):
        liste = liste[0]
    for element in liste:
        print(element, end=' ')
    print()

# Code

def binary_search(arr, x):
    low = 0
    high = len(arr) - 1
    mid = 0
 
    while low <= high:
 
        mid = (high + low) // 2
 
        # If x is greater, ignore left half
        if arr[mid] > x:
            low = mid + 1
 
        # If x is smaller, ignore right half
        elif arr[mid] < x:
            high = mid - 1
 
        # means x is present at mid
        else:
            return mid
 
    # If we reach here, then the element was not present
    return low

n, q = inI()
diamonds = [(0, 0, 0)]*n
sumweights = [0]*n

for i in range(n):
    a, w, v = inI()
    diamonds[i] = (a, w, v)
diamonds.sort(key=lambda t: (t[2], 1e5-t[1]))

sumweights[n-1] = diamonds[n-1][0]*diamonds[n-1][1]
for i in range(n-2, -1, -1):
    sumweights[i] = sumweights[i+1] + diamonds[i][0]*diamonds[i][1]

for i in range(q):
    query = inIL()

    if query[0] == 1:
        v = diamonds[query[2]-1]
        diamonds[query[2]-1] = (v[0]+query[1], v[1], v[2])
        for i in range(query[2]):
            sumweights[i] += query[1]*diamonds[query[2]-1][1]
    elif query[0] == 2:
        v = diamonds[query[2]-1]
        diamonds[query[2]-1] = (v[0]-query[1], v[1], v[2])
        for i in range(query[2]):
            sumweights[i] -= query[1]*diamonds[query[2]-1][1]
    else:
        m = binary_search(sumweights, query[1])

        if m > 0 and m<n:
            print(sum([diamond[2]*diamond[0] for diamond in diamonds[m:]]) + min(diamonds[m-1][0], (query[1]-sumweights[m])//diamonds[m-1][1])*diamonds[m-1][2])
        elif m > 0:
            print(min(diamonds[m-1][0], query[1]//diamonds[m-1][1])*diamonds[m-1][2])
        else:
            print(sum([diamond[2]*diamond[0] for diamond in diamonds[m:]]))

