from itertools import accumulate n,m=map(int,input().split()) a=[[0]*(m+2)] + [[0]+[i for i in accumulate(map(int,input().split()))]+[0] for i in range(m)] + [[0]*(m+2)] cnt=[[0]*(m+2) for i in range(m+2)] for i in range(1,m+1): for j in range(1,m+1): a[i][j] += a[i-1][j] for i in range(1,m+1): for j in range(1,m+1): for k in range(i,m+1): for l in range(j,m+1): if a[k][l] - a[i-1][l] - a[k][j-1] + a[i-1][j-1] == 0: cnt[i][j] += 1 cnt[i][l+1] -= 1 cnt[k+1][j] -= 1 cnt[k+1][l+1] += 1 for i in range(1,m+1): for j in range(1,m): cnt[i][j+1] += cnt[i][j] for j in range(1,m+1): for i in range(1,m): cnt[i+1][j] += cnt[i][j] for _ in range(n): x,y=map(int,input().split()) print(cnt[x][y])