import sys import io, os input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline n, m = map(int, input().split()) A = [list(map(int, input().split())) for i in range(m)] s = [[0]*(m+1) for _ in range(m+1)] for i in range(m): for j in range(m): s[i+1][j+1] = s[i+1][j] + s[i][j+1] - s[i][j] + A[i][j] imos = [[0]*(m+1) for i in range(m+1)] # [i, k), [j, l) for i in range(m): for j in range(m): for k in range(i+1, m+1): for l in range(j+1, m+1): temp = s[k][l] - s[k][j] - s[i][l] + s[i][j] if temp == 0: imos[i][j] += 1 imos[i][l] -= 1 imos[k][j] -= 1 imos[k][l] += 1 for i in range(1, m+1): for j in range(m+1): imos[i][j] += imos[i-1][j] for j in range(1, m+1): for i in range(m+1): imos[i][j] += imos[i][j-1] for i in range(n): x, y = map(int, input().split()) x, y = x-1, y-1 print(imos[x][y])