def xor(a, b):
    if a == 0 and b == 0:
        c = 0
    elif a == 0 and b == 1:
        c = 1
    elif a == 1 and b == 0:
        c = 1
    else:
        c = 0
    return (c)
n, m, q = [int(i) for i in input().split(" ")]
matrica = []
nova_matrica =[]
for i in range(n):
    M = [int(X) for X in input().split(" ")]
    matrica.append(M)
rezerva = matrica
for j in range(q):
    matrica = rezerva
    nova_matrica = matrica
    x, y, k = [int(b) for b in input().split(" ")]
    for s in range(k):
        matrica = nova_matrica
        for p in range(n):
            for r in range(m):
                X = r + 1
                if X == m:
                    X = 0
                Y = p + 1
                if Y == n:
                    Y = 0
    
                a = matrica[p-1][r]
                b = matrica[p][X]
                c = matrica[Y][r]
                d = matrica[p][r-1]
                nova_matrica[p][r] = (xor(xor(xor(a,b), c), d))
    print(nova_matrica[x-1][y])