from itertools import permutations
from copy import deepcopy
N, M, K = map(int,input().split())
arrayOrigin = [list(map(int,input().split())) for row in range(N)]
rotates = [list(map(int,input().split())) for i in range(K)]

def rotation(r,c,s,array):

    row = r-s-1
    col = c-s-1

    if s==0:
        return

    before = array[row][col]
    while col<c+s-1:
        col+=1
        temp = array[row][col]
        array[row][col] = before
        before = temp
    while row<r+s-1:
        row+=1
        temp = array[row][col]
        array[row][col] = before
        before = temp
    while col>c-s-1:
        col-=1
        temp = array[row][col]
        array[row][col] = before
        before = temp
    while row>r-s-1:
        row-=1
        temp = array[row][col]
        array[row][col] = before
        before = temp

    rotation(r,c,s-1,array)

answer = float('INF')

for rotate in list(permutations(rotates,K)):
    array = deepcopy(arrayOrigin)
    for r,c,s in rotate:
        temp = []
        rotation(r,c,s,array)

    for row in array:
        if answer>sum(row):
            answer = sum(row)
print(answer)