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): if s[k][l] - s[k][j] - s[i][l] + s[i][j] == 0: imos[i][j] += 1 imos[i][l] -= 1 imos[k][j] -= 1 imos[k][l] += 1 for i in range(m+1): for j in range(m): imos[i][j+1] += imos[i][j] for j in range(m+1): for i in range(m): imos[i+1][j] += imos[i][j] #print(imos) for i in range(n): x, y = map(int, input().split()) print(imos[x-1][y-1])