import sys
from collections import defaultdict
INF = 1000 * 1000 * 1000 + 7
class VMType:
def __init__(self, cpu, mem, price):
self.cpu = cpu
self.mem = mem
self.price = price
vm_types = []
def find_vm_type(cpu, mem):
best_price = INF
ind = -1
for i in range(len(vm_types)):
if vm_types[i].cpu >= cpu and vm_types[i].mem >= mem and vm_types[i].price < best_price:
best_price = vm_types[i].price
ind = i
return ind
def main():
m, d = map(int, input().split())
for _ in range(m):
cpu, mem, price = map(int, input().split())
vm_types.append(VMType(cpu, mem, price))
vms_to_shutdown = []
containers_to_allocate = defaultdict(list)
t = int(input().strip())
j = -1
while True:
j += 1
if j >= t:
break
line = input().split()
e = int(line[0])
if e == -1:
return # :(
cnt = 1
if e == 0:
cnt = int(line[1])
containers_to_shutdown = []
vms_to_create = []
for _ in range(e):
line = input().split()
type_id = int(line[0])
if type_id == 1:
id, cpu, mem = map(int, line[1:])
vm_index = find_vm_type(cpu, mem)
vms_to_create.append((id, vm_index))
containers_to_allocate[j + d].append(id)
elif type_id == 2:
id = int(line[1])
containers_to_shutdown.append(id)
j -= 1
for _ in range(cnt):
j += 1
if j in containers_to_allocate:
print(len(vms_to_create) + len(vms_to_shutdown) + len(containers_to_allocate[j]), flush=False)
else:
print(len(vms_to_create) + len(vms_to_shutdown), flush=False)
for id, vm_index in vms_to_create:
print(f"1 {id} {vm_index + 1}", flush=False)
for id in vms_to_shutdown:
print(f"2 {id}", flush=False)
if j in containers_to_allocate:
for id in containers_to_allocate[j]:
print(f"3 {id} {id}", flush=False)
vms_to_shutdown = containers_to_shutdown.copy()
containers_to_shutdown.clear()
vms_to_create.clear()
sys.stdout.flush()
e = int(input().strip())
if e == 0:
pass # :)
elif e == 1:
pass # :(
if __name__ == "__main__":
main()