#define _USE_MATH_DEFINES
#include<iostream>
#include<sstream> 
#include<cmath>
#include<math.h>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<conio.h>
#include<numeric>
#include<map>
#include<set>
#include<stack>
#include<stdlib.h>  
#include<unordered_map>
#include <queue>
using namespace std;

#define int long long

int pronadji(vector<pair<int, int>>& a, int n, int l, int r, int x) {
    int ans = 0;
    for (int i = l; i <= r; i++) {
        if (((x - a[i].first) | (a[i].second - x)) >= 0) {
            ans++;
        }
    }
    return ans;
}

int32_t main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n, m, l, r, x;
    cin >> n >> m;
    pair<int, int>par;
    vector<pair<int, int>>vage(n);
    for (int i = 0; i < n; i++) {
        cin >> par.first >> par.second;
        vage[i] = par;
    }
    for (int i = 0; i < m; i++) {
        cin >> l >> r >> x;
        cout << pronadji(vage, n, l-1, r-1, x) << '\n';
    }
    
    return 0;
}