import sys import numpy as np input = sys.stdin.buffer.readline 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) del A idx = np.argwhere(acc[:, None, :, None] + acc[None, :, None, :] - acc[:, None, None, :] - acc[None, :, :, None] == 0).T idx = idx[:, (idx[0] < idx[1]) & (idx[2] < idx[3])] imos = np.zeros((M + 1, M + 1), dtype=np.int64) np.add.at(imos, (idx[0], idx[2]), 1) np.add.at(imos, (idx[1], idx[3]), 1) np.subtract.at(imos, (idx[0], idx[3]), 1) np.subtract.at(imos, (idx[1], idx[2]), 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])