Nuske has a grid with N rows and M columns of squares. The rows are numbered 1 through N from top to bottom, and the columns are numbered 1 through M from left to right. Each square in the grid is painted in either blue or white. If S_{i,j} is 1, the square at the i-th row and j-th column is blue; if S_{i,j} is 0, the square is white. For every pair of two blue square a and b, there is at most one path that starts from a, repeatedly proceeds to an adjacent (side by side) blue square and finally reaches b, without traversing the same square more than once.

Phantom Thnook, Nuske's eternal rival, gives Q queries to Nuske. The i-th query consists of four integers x_{i,1}, y_{i,1}, x_{i,2} and y_{i,2} and asks him the following: when the rectangular region of the grid bounded by (and including) the x_{i,1}-th row, x_{i,2}-th row, y_{i,1}-th column and y_{i,2}-th column is cut out, how many connected components consisting of blue squares there are in the region?

Process all the queries.

Constraints

* 1 ≤ N,M ≤ 2000
* 1 ≤ Q ≤ 200000
* S_{i,j} is either 0 or 1.
* S_{i,j} satisfies the condition explained in the statement.
* 1 ≤ x_{i,1} ≤ x_{i,2} ≤ N(1 ≤ i ≤ Q)
* 1 ≤ y_{i,1} ≤ y_{i,2} ≤ M(1 ≤ i ≤ Q)

Input

The input is given from Standard Input in the following format:


N M Q
S_{1,1}..S_{1,M}
:
S_{N,1}..S_{N,M}
x_{1,1} y_{i,1} x_{i,2} y_{i,2}
:
x_{Q,1} y_{Q,1} x_{Q,2} y_{Q,2}


Output

For each query, print the number of the connected components consisting of blue squares in the region.

Examples

Input

3 4 4
1101
0110
1101
1 1 3 4
1 1 3 1
2 2 3 4
1 2 2 4


Output

3
2
2
2


Input

5 5 6
11010
01110
10101
11101
01010
1 1 5 5
1 2 4 5
2 3 3 4
3 3 3 3
3 1 3 5
1 1 3 4


Output

3
2
1
1
3
2

Difficulty: UNKNOWN_DIFFICULTY

Solutions:
def main():
	import sys
	input = sys.stdin.readline
	(H, W, Q) = map(int, input().split())
	S = [list(map(lambda x: x == '1', input())) for _ in range(H)]
	(M, L, R, U, D) = ([], [], [], [], [])
	for (x, s) in enumerate(S):
		(M_, L_, R_, U_, D_) = ([], [], [], [], [])
		for (y, c) in enumerate(s):
			m = l = r = u = d = 0
			if c:
				if x >= 1:
					m += S[x - 1][y]
					u -= S[x - 1][y]
				if x < H - 1:
					m += S[x + 1][y]
					d -= S[x + 1][y]
				if y >= 1:
					m += s[y - 1]
					l -= s[y - 1]
				if y < W - 1:
					m += s[y + 1]
					r -= s[y + 1]
				m = 2 - m
			M_.append(m)
			L_.append(l)
			R_.append(r)
			U_.append(u)
			D_.append(d)
		M.append(M_)
		L.append(L_)
		R.append(R_)
		U.append(U_)
		D.append(D_)
	M.append([0] * (W + 1))
	L.append([0] * (W + 1))
	R.append([0] * (W + 1))
	U.append([0] * (W + 1))
	D.append([0] * (W + 1))
	for x in range(H):
		m = 0
		for y in range(W):
			m += M[x][y]
			M[x][y] = m + M[x - 1][y]
			L[x][y] += L[x - 1][y]
			R[x][y] += R[x - 1][y]
			U[x][y] += U[x][y - 1]
			D[x][y] += D[x][y - 1]
	Ans = []
	for _ in range(Q):
		(x1, y1, x2, y2) = map(int, input().split())
		ans = 0
		ans += M[x2 - 1][y2 - 1] + M[x1 - 2][y1 - 2] - M[x2 - 1][y1 - 2] - M[x1 - 2][y2 - 1]
		ans -= L[x2 - 1][y1 - 1] - L[x1 - 2][y1 - 1]
		ans -= R[x2 - 1][y2 - 1] - R[x1 - 2][y2 - 1]
		ans -= U[x1 - 1][y2 - 1] - U[x1 - 1][y1 - 2]
		ans -= D[x2 - 1][y2 - 1] - D[x2 - 1][y1 - 2]
		assert ans % 2 == 0, ans
		print(ans // 2)
main()


(n, m, q) = map(int, input().split())
(s, v, el, eu) = ([[0] * (m + 2) for _ in range(n + 2)] for _ in range(4))
for i in range(1, n + 1):
	s[i][1:m + 1] = map(int, input())
	for j in range(1, m + 1):
		v[i][j] = v[i][j - 1] + s[i][j]
		el[i][j] = el[i][j - 1] + s[i][j] * s[i][j - 1]
		eu[i][j] = eu[i][j - 1] + s[i][j] * s[i - 1][j]
for i in range(2, n + 1):
	for j in range(1, m + 1):
		v[i][j] += v[i - 1][j]
		el[i][j] += el[i - 1][j]
		eu[i][j] += eu[i - 1][j]
for _ in range(q):
	(x1, y1, x2, y2) = map(int, input().split())
	print(v[x2][y2] - v[x1 - 1][y2] - v[x2][y1 - 1] + v[x1 - 1][y1 - 1] - (el[x2][y2] - el[x1 - 1][y2] - el[x2][y1] + el[x1 - 1][y1]) - (eu[x2][y2] - eu[x1][y2] - eu[x2][y1 - 1] + eu[x1][y1 - 1]))


import sys
from itertools import accumulate
readline = sys.stdin.readline

def accumulate2d(X):
	N = len(X)
	M = len(X[0])
	for i in range(1, N):
		for j in range(1, M):
			X[i][j] += X[i][j - 1]
	for j in range(1, M):
		for i in range(1, N):
			X[i][j] += X[i - 1][j]
	return X
(N, M, Q) = map(int, readline().split())
G = [[0] * (M + 2)] + [[0] + list(map(int, readline().strip())) + [0] for _ in range(N)] + [[0] * (M + 2)]
U = [[0] * (M + 2) for _ in range(N + 2)]
L = [[0] * (M + 2) for _ in range(N + 2)]
for i in range(1, N + 1):
	for j in range(1, M + 1):
		if G[i][j]:
			if G[i - 1][j]:
				U[i][j] += 1
			if G[i][j - 1]:
				L[i][j] += 1
G = accumulate2d(G)
L = accumulate2d(L)
U = accumulate2d(U)
Ans = [None] * Q
for qu in range(Q):
	(x1, y1, x2, y2) = map(int, readline().split())
	u = U[x1][y1 - 1] + U[x2][y2] - U[x1][y2] - U[x2][y1 - 1]
	l = L[x1 - 1][y1] + L[x2][y2] - L[x1 - 1][y2] - L[x2][y1]
	g = G[x1 - 1][y1 - 1] + G[x2][y2] - G[x1 - 1][y2] - G[x2][y1 - 1]
	Ans[qu] = g - u - l
print('\n'.join(map(str, Ans)))


def solve():
	import sys
	input = sys.stdin.readline
	(N, M, Q) = map(int, input().split())
	Sss = [input().rstrip() for _ in range(N)]
	numVertexss = [[0] * (M + 1)] + [[0] + list(map(int, Ss)) for Ss in Sss]
	numEdgeVss = [[0] * (M + 1) for _ in range(N + 1)]
	numEdgeHss = [[0] * (M + 1) for _ in range(N + 1)]
	for i in range(1, N):
		for j in range(1, M + 1):
			if numVertexss[i][j] and numVertexss[i + 1][j]:
				numEdgeVss[i][j] = 1
	for i in range(1, N + 1):
		for j in range(1, M):
			if numVertexss[i][j] and numVertexss[i][j + 1]:
				numEdgeHss[i][j] = 1

	def getAccAss(Ass):
		for x in range(1, N + 1):
			for y in range(M + 1):
				Ass[x][y] += Ass[x - 1][y]
		for x in range(N + 1):
			for y in range(1, M + 1):
				Ass[x][y] += Ass[x][y - 1]

	def getRangeSum2D(accAss, xFr, xTo, yFr, yTo):
		return accAss[xTo + 1][yTo + 1] - accAss[xTo + 1][yFr] - accAss[xFr][yTo + 1] + accAss[xFr][yFr]
	getAccAss(numVertexss)
	getAccAss(numEdgeVss)
	getAccAss(numEdgeHss)
	anss = []
	for _ in range(Q):
		(x1, y1, x2, y2) = map(int, input().split())
		(x1, y1, x2, y2) = (x1 - 1, y1 - 1, x2 - 1, y2 - 1)
		ans = getRangeSum2D(numVertexss, x1, x2, y1, y2)
		ans -= getRangeSum2D(numEdgeVss, x1, x2 - 1, y1, y2)
		ans -= getRangeSum2D(numEdgeHss, x1, x2, y1, y2 - 1)
		anss.append(ans)
	print('\n'.join(map(str, anss)))
solve()


def examA():
	(N, A, B) = LI()
	if N == 1:
		if A == B:
			print(1)
		else:
			print(0)
		return
	ans = (N - 2) * max(B - A, 0) + 1
	if B < A:
		ans = 0
	print(ans)
	return

def examB():
	S = SI()
	N = len(S)
	cnt = 0
	for (i, s) in enumerate(S):
		cnt += N - 1
		if s == 'U':
			cnt += i
		else:
			cnt += N - i - 1
	ans = cnt
	print(ans)
	return

def examC():
	(N, M, q) = LI()
	S = [SI() for _ in range(N)]
	Q = [LI() for _ in range(q)]
	S1 = [[0] * (M + 1) for _ in range(N + 1)]
	S2 = [[0] * (M + 1) for _ in range(N + 1)]
	S3 = [[0] * (M + 1) for _ in range(N + 1)]
	for i in range(N):
		now = 0
		for j in range(M):
			now += int(S[i][j])
			S1[i + 1][j + 1] = S1[i][j + 1] + now
	for i in range(N):
		now = 0
		for j in range(M - 1):
			if S[i][j] == '1' and S[i][j + 1] == '1':
				now += 1
			S2[i + 1][j + 1] += S2[i][j + 1] + now
	for i in range(M):
		now = 0
		for j in range(N - 1):
			if S[j][i] == '1' and S[j + 1][i] == '1':
				now += 1
			S3[j + 1][i + 1] += S3[j + 1][i] + now
	ans = [0] * q
	for i in range(q):
		(x1, y1, x2, y2) = Q[i]
		x1 -= 1
		y1 -= 1
		cur = S1[x2][y2] - S1[x1][y2] - S1[x2][y1] + S1[x1][y1]
		cur -= S2[x2][y2 - 1] - S2[x1][y2 - 1] - S2[x2][y1] + S2[x1][y1]
		cur -= S3[x2 - 1][y2] - S3[x1][y2] - S3[x2 - 1][y1] + S3[x1][y1]
		ans[i] = cur
	for v in ans:
		print(v)
	return

def examD():
	A = I()
	B = I()
	ans = 0
	print(ans)
	return

def examE():
	ans = 0
	print(ans)
	return

def examF():
	ans = 0
	print(ans)
	return

def test():
	return
import sys, bisect, itertools, heapq, math, random
from copy import deepcopy
from heapq import heappop, heappush, heapify
from collections import Counter, defaultdict, deque
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

def I():
	return int(readline())

def LI():
	return list(map(int, sys.stdin.readline().split()))

def LSI():
	return list(map(str, sys.stdin.readline().split()))

def LS():
	return sys.stdin.readline().split()

def SI():
	return sys.stdin.readline().strip()
global mod, mod2, inf, alphabet, _ep
mod = 10 ** 9 + 7
mod2 = 998244353
inf = 10 ** 18
_ep = 10 ** (-12)
alphabet = [chr(ord('a') + i) for i in range(26)]
sys.setrecursionlimit(10 ** 7)
examC()


import sys
from itertools import accumulate

def solve():
	(n, m, q) = map(int, input().split())
	s = [[int(j) for j in input()] for i in range(n)]
	sxy = [list(accumulate(s[i])) for i in range(n)]
	for j in range(m):
		for i in range(n - 1):
			sxy[i + 1][j] += sxy[i][j]
	exy = [[0] * (2 * m) for i in range(2 * n)]
	for i in range(2 * n - 1):
		if i % 2 == 0:
			for j in range(2 * m - 1):
				exy[i][j + 1] += exy[i][j]
				if j % 2 == 0 and j < 2 * m - 2:
					exy[i][j + 1] += s[i // 2][j // 2] == s[i // 2][j // 2 + 1] == 1
		else:
			for j in range(2 * m - 1):
				if j % 2 == 0:
					exy[i][j] += s[i // 2][j // 2] == s[i // 2 + 1][j // 2] == 1
				exy[i][j + 1] += exy[i][j]
	for j in range(2 * m):
		for i in range(2 * n - 1):
			exy[i + 1][j] += exy[i][j]
	for qi in range(q):
		(x1, y1, x2, y2) = map(lambda x: x - 1, map(int, sys.stdin.readline().split()))
		nv = sxy[x2][y2]
		if x1 - 1 >= 0:
			nv -= sxy[x1 - 1][y2]
		if y1 - 1 >= 0:
			nv -= sxy[x2][y1 - 1]
		if x1 - 1 >= 0 and y1 - 1 >= 0:
			nv += sxy[x1 - 1][y1 - 1]
		ne = exy[2 * x2][2 * y2]
		if 2 * x1 - 1 >= 0:
			ne -= exy[2 * x1 - 1][2 * y2]
		if 2 * y1 - 1 >= 0:
			ne -= exy[2 * x2][2 * y1 - 1]
		if 2 * x1 - 1 >= 0 and 2 * y1 - 1 >= 0:
			ne += exy[2 * x1 - 1][2 * y1 - 1]
		ans = nv - ne
		print(ans)
solve()


import gc

class Ruiseki2D:

	def __init__(self, matrix):
		self.h = len(matrix)
		self.w = len(matrix[0])
		self.ruiseki = [[0] * (self.w + 1) for _ in range(self.h + 1)]
		for i in range(self.h):
			for j in range(self.w):
				self.ruiseki[i + 1][j + 1] = self.ruiseki[i + 1][j] + matrix[i][j]
		for i in range(self.h):
			for j in range(self.w):
				self.ruiseki[i + 1][j + 1] += self.ruiseki[i][j + 1]

	def get_sum(self, hl, hr, wl, wr):
		return self.ruiseki[hr][wr] + self.ruiseki[hl][wl] - self.ruiseki[hr][wl] - self.ruiseki[hl][wr]
(n, m, q) = map(int, input().split())
s = [list(map(int, input())) for i in range(n)]
query = [list(map(int, input().split())) for i in range(q)]
ru_col_cnt = Ruiseki2D(s)
yoko_edge = [[0] * (m + 1) for i in range(n + 1)]
for i in range(n):
	for j in range(m - 1):
		if s[i][j] == 1 and s[i][j + 1] == 1:
			yoko_edge[i + 1][j + 1] = 1
for i in range(n):
	for j in range(m):
		yoko_edge[i + 1][j + 1] += yoko_edge[i + 1][j]
for i in range(n):
	for j in range(m):
		yoko_edge[i + 1][j + 1] += yoko_edge[i][j + 1]
tate_edge = [[0] * (m + 1) for i in range(n + 1)]
for i in range(n - 1):
	for j in range(m):
		if s[i][j] == 1 and s[i + 1][j] == 1:
			tate_edge[i + 1][j + 1] = 1
for i in range(n):
	for j in range(m):
		tate_edge[i + 1][j + 1] += tate_edge[i + 1][j]
for i in range(n):
	for j in range(m):
		tate_edge[i + 1][j + 1] += tate_edge[i][j + 1]

def yoko_get_sum(hl, hr, wl, wr):
	return yoko_edge[hr][wr] + yoko_edge[hl][wl] - yoko_edge[hr][wl] - yoko_edge[hl][wr]

def tate_get_sum(hl, hr, wl, wr):
	return tate_edge[hr][wr] + tate_edge[hl][wl] - tate_edge[hr][wl] - tate_edge[hl][wr]
for (hl, wl, hr, wr) in query:
	(hl, wl) = (hl - 1, wl - 1)
	ans = ru_col_cnt.get_sum(hl, hr, wl, wr)
	ans -= yoko_get_sum(hl, hr, wl, wr - 1) + tate_get_sum(hl, hr - 1, wl, wr)
	print(ans)


def get(a, b, c, d, dp):
	return dp[c][d] - dp[a][d] - dp[c][b] + dp[a][b]
(n, m, q) = map(int, input().split())
s = [list(map(int, list(input()))) for _ in range(n)]
vers = [[0] * (m + 1) for i in range(n + 1)]
edges = [[0] * (m + 1) for i in range(n + 1)]
tate = [[0] * (m + 1) for i in range(n + 1)]
yoko = [[0] * (m + 1) for i in range(n + 1)]
for i in range(n):
	for j in range(m):
		if s[i][j] == 0:
			continue
		vers[i + 1][j + 1] = 1
		(nx, ny) = (i + 1, j)
		if 0 <= nx < n and 0 <= ny < m and (s[nx][ny] == 1):
			edges[i + 1][j + 1] += 1
			edges[i + 2][j + 1] += 1
			tate[i + 1][j + 1] += 1
		(nx, ny) = (i, j + 1)
		if 0 <= nx < n and 0 <= ny < m and (s[nx][ny] == 1):
			edges[i + 1][j + 1] += 1
			edges[i + 1][j + 2] += 1
			yoko[i + 1][j + 1] += 1
for i in range(1, n + 1):
	for j in range(1, m + 1):
		vers[i][j] += vers[i][j - 1]
		edges[i][j] += edges[i][j - 1]
		tate[i][j] += tate[i][j - 1]
for j in range(1, m + 1):
	for i in range(1, n + 1):
		vers[i][j] += vers[i - 1][j]
		edges[i][j] += edges[i - 1][j]
		yoko[i][j] += yoko[i - 1][j]
for _ in range(q):
	(a, b, c, d) = map(int, input().split())
	a -= 1
	b -= 1
	vcnt = get(a, b, c, d, vers)
	ecnt = get(a, b, c, d, edges)
	ecnt -= yoko[c][b] - yoko[a][b]
	ecnt -= tate[a][d] - tate[a][b]
	ecnt -= yoko[c][d] - yoko[a][d]
	ecnt -= tate[c][d] - tate[c][b]
	ecnt //= 2
	print(vcnt - ecnt)