import itertools import numpy as np N, M = map(int, input().split()) A = np.zeros((M + 1, M + 1), dtype=np.int64) A[1:, 1:] = np.array([tuple(map(int, input().split())) for _ in range(M)]) acc = A.cumsum(axis=0).cumsum(axis=1).tolist() imos = [[0] * (M + 1) for _ in range(M + 1)] for x1, x2 in itertools.combinations(range(M + 1), 2): for y1, y2 in itertools.combinations(range(M + 1), 2): if acc[x1][y1] + acc[x2][y2] == acc[x1][y2] + acc[x2][y1]: imos[x1][y1] += 1 imos[x2][y2] += 1 imos[x1][y2] -= 1 imos[x2][y1] -= 1 imos = np.array(imos).cumsum(axis=0).cumsum(axis=1) for _ in range(N): x, y = ((int(a) - 1) for a in input().split()) print(imos[x, y])