Buggy python submission (verdict: Time Limit Exceeded):
def main():
    import numpy as np
    n, m, q = map(int, input().split())
    ten = np.zeros((n+1, m+1), dtype=np.int32)
    ten[1:, 1:] = np.array([list(map(lambda x:int(x), list(input())))
                            for _ in [0]*n], dtype=np.int32)

    hen1 = np.zeros((n+1, m), dtype=np.int32)
    hen1[1:, 1:] = ten[1:, 1:m] & ten[1:, 2:]
    hen1 = np.cumsum(hen1, axis=0)
    hen1 = np.cumsum(hen1, axis=1)
    hen2 = np.zeros((n, m+1), dtype=np.int32)
    hen2[1:, 1:] = ten[1:n, 1:] & ten[2:, 1:]
    hen2 = np.cumsum(hen2, axis=0)
    hen2 = np.cumsum(hen2, axis=1)
    ten = np.cumsum(ten, axis=0)
    ten = np.cumsum(ten, axis=1)

    for i in range(q):
        x1, y1, x2, y2 = map(int, input().split())
        temp = -hen1[x2][y2-1]-hen1[x1-1][y1-1]+hen1[x2][y1-1]+hen1[x1-1][y2-1]
        temp -= hen2[x2-1][y2]+hen2[x1-1][y1-1]-hen2[x2-1][y1-1]-hen2[x1-1][y2]
        print(temp+ten[x2][y2]+ten[x1-1][y1-1]-ten[x2][y1-1]-ten[x1-1][y2])


main()

Fixed submission:
def main():
    from itertools import accumulate as ac
    n, m, q = map(int, input().split())
    ten = [list(map(lambda x:x == "1", list(input()))) for _ in [0]*n]
    xy = [list(map(int, input().split())) for _ in [0]*q]
    ans = [0]*q

    hen = [[0]*m]+[None]*n
    for i in range(n):
        temp = [0]
        for j in range(m-1):
            temp.append(ten[i][j] & ten[i][j+1])
        hen[i+1] = list(ac(temp))
    for i in range(n):
        for j in range(1, m):
            hen[i+1][j] += hen[i][j]

    for i, (x1, y1, x2, y2) in enumerate(xy):
        ans[i] = -hen[x2][y2-1]-hen[x1-1][y1-1] + \
            hen[x2][y1-1]+hen[x1-1][y2-1]

    hen = [[0]*(m+1)]+[None]*(n-1)
    for i in range(n-1):
        temp = [0]
        for j in range(m):
            temp.append(ten[i][j] & ten[i+1][j])
        hen[i+1] = list(ac(temp))
    for i in range(n-1):
        for j in range(1, m+1):
            hen[i+1][j] += hen[i][j]

    for i, (x1, y1, x2, y2) in enumerate(xy):
        ans[i] -= hen[x2-1][y2]+hen[x1-1][y1-1] - \
            hen[x2-1][y1-1]-hen[x1-1][y2]

    del hen

    ten = [[0]*(m+1)]+ten
    for i in range(1, n+1):
        ten[i] = [0]+list(ac(ten[i]))
    for i in range(n):
        for j in range(1, m+1):
            ten[i+1][j] += ten[i][j]

    for i, (x1, y1, x2, y2) in enumerate(xy):
        print(ans[i]+ten[x2][y2]+ten[x1-1][y1-1]-ten[x2][y1-1]-ten[x1-1][y2])


main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    from itertools import accumulate as ac
    n, m, q = map(int, input().split())
    ten = [list(map(lambda x:x == "1", list(input()))) for _ in [0]*n]
    hen1 = [[0]*m]+[[0]+list(ac([ten[i][j] & ten[i][j+1] for j in range(m-1)]))
                    for i in range(n)]
    hen2 = [[0]*(m+1)]+[[0]+list(ac([ten[i][j] & ten[i+1][j] for j in range(m)]))
                        for i in range(n-1)]

    ten = [[0]*(m+1)]+[[0]+list(ac(j)) for j in ten]
    for i in range(n):
        for j in range(1, m+1):
            ten[i+1][j] += ten[i][j]
    for i in range(n):
        for j in range(1, m):
            hen1[i+1][j] += hen1[i][j]
    for i in range(n-1):
        for j in range(1, m+1):
            hen2[i+1][j] += hen2[i][j]

    for _ in range(q):
        x1, y1, x2, y2 = map(int, input().split())
        ans = ten[x2][y2]+ten[x1-1][y1-1]-ten[x2][y1-1]-ten[x1-1][y2]
        ans -= hen1[x2][y2-1]+hen1[x1-1][y1-1]-hen1[x2][y1-1]-hen1[x1-1][y2-1]
        ans -= hen2[x2-1][y2]+hen2[x1-1][y1-1]-hen2[x2-1][y1-1]-hen2[x1-1][y2]
        print(ans)


main()


Fixed submission:
def main():
    from itertools import accumulate as ac
    n, m, q = map(int, input().split())
    ten = [list(map(lambda x:x == "1", list(input()))) for _ in [0]*n]
    xy = [list(map(int, input().split())) for _ in [0]*q]
    ans = [0]*q

    hen = [[0]*m]+[None]*n
    for i in range(n):
        temp = [0]
        for j in range(m-1):
            temp.append(ten[i][j] & ten[i][j+1])
        hen[i+1] = list(ac(temp))
    for i in range(n):
        for j in range(1, m):
            hen[i+1][j] += hen[i][j]

    for i, (x1, y1, x2, y2) in enumerate(xy):
        ans[i] = -hen[x2][y2-1]-hen[x1-1][y1-1] + \
            hen[x2][y1-1]+hen[x1-1][y2-1]

    hen = [[0]*(m+1)]+[None]*(n-1)
    for i in range(n-1):
        temp = [0]
        for j in range(m):
            temp.append(ten[i][j] & ten[i+1][j])
        hen[i+1] = list(ac(temp))
    for i in range(n-1):
        for j in range(1, m+1):
            hen[i+1][j] += hen[i][j]

    for i, (x1, y1, x2, y2) in enumerate(xy):
        ans[i] -= hen[x2-1][y2]+hen[x1-1][y1-1] - \
            hen[x2-1][y1-1]-hen[x1-1][y2]

    del hen

    ten = [[0]*(m+1)]+ten
    for i in range(1, n+1):
        ten[i] = [0]+list(ac(ten[i]))
    for i in range(n):
        for j in range(1, m+1):
            ten[i+1][j] += ten[i][j]

    for i, (x1, y1, x2, y2) in enumerate(xy):
        print(ans[i]+ten[x2][y2]+ten[x1-1][y1-1]-ten[x2][y1-1]-ten[x1-1][y2])


main()