from itertools import accumulate import sys def MI(): return map(int, sys.stdin.readline().split()) int1 = lambda x: int(x) - 1 def MI1(): return map(int1, sys.stdin.readline().split()) def main(): n,m=MI() bb=[[0]*(m+1)]+[[0]+[b for b in accumulate(MI())] for _ in range(m)] 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()