import sys input = sys.stdin.readline N, M = map(int, input().split()) A = [[0 for _ in range(M+1)]] for _ in range(M): Ai = list(map(int, input().split())) Ai.insert(0, 0) A.append(Ai) for i in range(M): for j in range(M): A[i+1][j+1] += A[i+1][j] + A[i][j+1] - A[i][j] imos = [[0 for _ in range(M)] for _ in range(M)] for i in range(M): for j in range(M): for k in range(i, M): for l in range(j, M): if A[k+1][l+1] - A[k+1][j] - A[i][l+1] + A[i][j] == 0: imos[i][j] += 1 if k + 1 < M and l + 1 < M: imos[k+1][j] -= 1 imos[i][l+1] -= 1 imos[k+1][l+1] += 1 elif k + 1 < M: imos[k+1][j] -= 1 elif l + 1 < M: imos[i][l+1] -= 1 for i in range(M): for j in range(1, M): imos[i][j] += imos[i][j-1] for i in range(1, M): for j in range(M): imos[i][j] += imos[i-1][j] for _ in range(N): xi, yi = map(int, input().split()) print(imos[xi-1][yi-1])