# Baekjoon-17822-원판 돌리기

from collections import deque
N,M,T = map(int,input().split())

board = [[]]
for _ in range(N):
board.append(list(map(int,input().split())))
head =  * (N+1) # index of top element

for _ in range(T):
x,d,k = map(int,input().split())

# debug
# print('-------------------')
# for i in range(1,N+1):
#     for j in range(M):
#     print()

# 회전
for i in range(0,N+1,x):

# 인접 수 찾기
visited = [ * M for _ in range(N+1)]
visited = 1
sames = []
is_removed = False
total_sum, total_count = 0,0
for i in range(1,N+1):
for j in range(M):
continue
else:
total_count += 1

for ni,nj in [[i,(j+1)%M],[i,(j-1)%M],[i+1,j],[i-1,j]]:
if 1<=ni<=N:
visited[i][j] = 2
visited[ni][nj] = 2
is_removed = True

# debug
# print('-------------------')
# for i in range(1,N+1):
#     for j in range(M):
#     print()

if total_count == 0:
print(0)
exit()
avg = total_sum / total_count
for i in range(1,N+1):
for j in range(M):
if not is_removed:
if board[i][j] != 0:
if board[i][j] > avg:
board[i][j] = board[i][j]-1
elif board[i][j] < avg:
board[i][j] = board[i][j]+1
elif visited[i][j] == 2:

# debug
# print('-------------------')
# for i in range(1,N+1):
#     for j in range(M):