N,M=map(int,input().split()) F=[[0]*(M+1)] for _ in range(M): F.append([0]+list(map(int,input().split()))) Q=[list(map(int,input().split())) for _ in range(N)] for i in range(M+1): for j in range(1,M+1): F[i][j]+=F[i][j-1] for j in range(M+1): for i in range(1,M+1): F[i][j]+=F[i-1][j] # print(F) ans=[[0]*(M+1) for _ in range(M+1)] for x1 in range(1,M+1): for y1 in range(1,M+1): for x2 in range(x1,M+1): for y2 in range(y1,M+1): if F[x2][y2]-F[x1-1][y2]-F[x2][y1-1]+F[x1-1][y1-1]==0: ans[x1-1][y1-1]+=1 ans[x1-1][y2]-=1 ans[x2][y1-1]-=1 ans[x2][y2]+=1 for i in range(M+1): for j in range(M): ans[i][j+1]+=ans[i][j] for j in range(M+1): for i in range(M): ans[i+1][j]+=ans[i][j] for x,y in Q: print(ans[x-1][y-1])