def main(): n, m = map(int, input().split()) A = [list(map(int, input().split())) for i in range(m)] s = [[0]*(m+1) for _ in range(m+1)] for i in range(m): for j in range(m): s[i+1][j+1] = s[i+1][j] + s[i][j+1] - s[i][j] + A[i][j] #print(s) imos = [[0]*(m+1) for i in range(m+1)] # [i, k), [j, l) for i in range(n): for j in range(n): for k in range(i+1, n+1): for l in range(j+1, n+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]) if __name__ == '__main__': main()