block = { #寬, 高, 格子數
"A": (1, 4, 4),
"B": (3, 1, 3),
"C": (2, 2, 4),
"D": (3, 2, 4),
"E": (2, 3, 5)
}
r, c, n = map(int, input().split())
total_block = r*c #總空格數
out = 0 #要被丟掉的貨物
row = [0 for i in range(r)] #計算距離
for i in range(n):
block_type, top = input().split() #貨物種類、天花板距離
top = int(top)
bottom = top + block[block_type][1]
clone_row = row[:][top:bottom] #這邊要deepclone否則會改到原資料
print(clone_row)
print(" ", '0', clone_row)
for index in range(block[block_type][1]): #D跟E比較麻煩要拉出來算
if block_type == 'D' and index == 0:
clone_row[index] += 1
elif block_type == 'E' and index == 0:
clone_row[index] += 1
else:
clone_row[index] += block[block_type][0]
print(" ", index, clone_row)
max_R = max(clone_row)
if max_R > c: #判斷該貨物是否要被丟棄
out += 1
else:
row[top:bottom] = [max_R for j in range(block[block_type][1])]
#確定最終高度再一起改回到原row
total_block -= block[block_type][2]
print(total_block, out)