# Baekjoon-17143-낚시왕

R,C,M = map(int,input().split())
shark = [[[] for _ in range(C)] for _ in range(R)]
dirs = [[-1,0],[1,0],[0,1],[0,-1]]
for _ in range(M):
r,c,s,d,z = map(int,input().split())
shark[r-1][c-1] = [dirs[d-1]*s,dirs[d-1]*s,z] # vx, vy, size

result = 0
for c in range(C):
# fishing
for r in range(R):
if len(shark[r][c]) != 0:
result += shark[r][c][-1]
shark[r][c] = []
break

# print shark
# p_shark = [*C for _ in range(R)]
# for i in range(R):
#     for j in range(C):
#         if len(shark[i][j]):
#             p_shark[i][j] = shark[i][j][-1]
# print('--------------')
# print(*p_shark,sep='\n')

# shark move
new_shark = [[[] for line in s] for s in shark]
for i in range(R):
for j in range(C):
if len(shark[i][j]):
vx,vy,size = shark[i][j]
nx,ny = i+vx, j+vy
if (nx // (R-1))%2==0:
nx = nx%(R-1)
nvx = vx
else:
nx = (R-1)-(nx%(R-1))
nvx = -vx
if (ny // (C-1))%2==0:
ny = ny%(C-1)
nvy = vy
else:
ny = (C-1)-(ny%(C-1))
nvy = -vy
if len(new_shark[nx][ny]):
if new_shark[nx][ny][-1] < size:
new_shark[nx][ny] = [nvx,nvy,size]
else:
new_shark[nx][ny] = [nvx,nvy,size]
shark = new_shark

print(result)