n, m = map(int, input().split()) l = [[0]*(m+1)] + [[0] + list(map(int, input().split())) for _ in range(m)] g = [[0]*(m+1) for _ in range(m+1)] for i in range(m): for j in range(m): l[i+1][j+1] += l[i+1][j] for i in range(m): for j in range(m): l[i+1][j+1] += l[i][j+1] for i in range(m): for a in range(i+1, m+1): for j in range(m): for b in range(j+1, m+1): if l[a][b] - l[i][b] - l[a][j] + l[i][j] == 0: g[i][j] += 1 g[a][b] += 1 g[i][b] -= 1 g[a][j] -= 1 for i in range(m+1): for j in range(m): g[i][j+1] += g[i][j] for j in range(m+1): for i in range(m): g[i+1][j] += g[i][j] for _ in range(n): x, y = map(int, input().split()) print(g[x-1][y-1])