import sys def II(): return int(sys.stdin.readline()) def MI(): return map(int, sys.stdin.readline().split()) def LI(): return list(map(int, sys.stdin.readline().split())) def SI(): return sys.stdin.readline()[:-1] def LLI(rows_number): return [LI() for _ in range(rows_number)] def LLI1(rows_number): return [LI1() for _ in range(rows_number)] int1 = lambda x: int(x) - 1 def MI1(): return map(int1, sys.stdin.readline().split()) def LI1(): return list(map(int1, sys.stdin.readline().split())) p2D = lambda x: print(*x, sep="\n") dij = [(1, 0), (0, 1), (-1, 0), (0, -1)] def main(): n,m=MI() aa=LLI(m) bb=[[0]*(m+1) for _ in range(m+1)] for i,row in enumerate(aa): for j,a in enumerate(row): bb[i+1][j+1]=bb[i+1][j]+a for j in range(m): for i in range(m): bb[i+1][j+1]+=bb[i][j+1] cc=[[0]*(m+1) for _ in range(m+1)] for si in range(m): for sj in range(m): for gi in range(si+1,m+1): for gj in range(sj+1,m+1): if bb[si][sj]+bb[gi][gj]-bb[si][gj]-bb[gi][sj]==0: cc[si][sj]+=1 cc[gi][gj]+=1 cc[si][gj]-=1 cc[gi][sj]-=1 for i in range(m+1): for j in range(m): cc[i][j+1]+=cc[i][j] for j in range(m+1): for i in range(m): cc[i+1][j]+=cc[i][j] for _ in range(n): i,j=MI1() print(cc[i][j]) main()