#include <iostream>
#include <vector>
#include <string>
#include <math.h>
using namespace std;

struct Vaga {
	int index;
	int donjaGr;
	int gornjaGr;
};

struct Pitanje {
	int od;
	int mdo;
	int tezina;
};

vector<int> Resenja;

void Ispisi(vector<int>& Vec, vector<int>::iterator It)
{
	if (It == Vec.end()) return;
	cout << *It << endl;
	Ispisi(Vec, ++It);
}

void ProdjiRacun(int mDo, int Tezina, int& Brojac, vector<Vaga>& Vage, vector<Vaga>::iterator It)
{
	if (It == Vage.begin() + (mDo)) return;
	Vaga trenop = *It;

	if (Tezina >= trenop.donjaGr && Tezina <= trenop.gornjaGr) ProdjiRacun(mDo, Tezina, ++Brojac, Vage, ++It);
	else ProdjiRacun(mDo, Tezina, Brojac, Vage, ++It);
}

void ProdjiPitanja(vector<Pitanje>& Pitanja, vector<Vaga>& Vage, vector<Pitanje>::iterator It)
{
	if (It == Pitanja.end()) return;
	int Brojac = 0;

	ProdjiRacun((*It).mdo, (*It).tezina, Brojac, Vage, Vage.begin() + ((*It).od - 1));
	Resenja.push_back(Brojac);

	ProdjiPitanja(Pitanja, Vage, ++It);
}

int main()
{
	vector<Vaga> vage;
	vector<Pitanje> pitanja;
	int brojVaga, brojPitanja;

	cin >> brojVaga >> brojPitanja;
	for (int i = 0; i < brojVaga; i++)
	{
		Vaga temp;
		cin >> temp.donjaGr >> temp.gornjaGr;
		temp.index = i + 1;
		vage.push_back(temp);
	}

	for (int i = 0; i < brojPitanja; i++)
	{
		Pitanje temp;
		cin >> temp.od >> temp.mdo >> temp.tezina;
		pitanja.push_back(temp);
	}

	ProdjiPitanja(pitanja, vage, pitanja.begin());

	Ispisi(Resenja, Resenja.begin());

}