import sys import io, os input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline from itertools import accumulate n, m = map(int, input().split()) s = [[0]*(m+1)]+[[0]+[a for a in accumulate(map(int,input().split()))] for _ in range(m)] for j in range(m): for i in range(m): s[i+1][j+1] += s[i][j+1] #print(s) imos = [[0]*(m+1) for i in range(m+1)] # [i, k), [j, l) for i in range(m): for j in range(m): for k in range(i+1, m+1): for l in range(j+1, m+1): temp = s[k][l] - s[k][j] - s[i][l] + s[i][j] if temp == 0: imos[i][j] += 1 imos[i][l] -= 1 imos[k][j] -= 1 imos[k][l] += 1 for i in range(1, m+1): for j in range(m+1): imos[i][j] += imos[i-1][j] for j in range(1, m+1): for i in range(m+1): imos[i][j] += imos[i][j-1] #print(imos) for i in range(n): x, y = map(int, input().split()) x, y = x-1, y-1 print(imos[x][y])