#include<cstdio>
#include<cstring>
#include<algorithm>
#define LL long long
using namespace std;
const int M=1e6+7;
LL read(){
    LL ans=0,f=1,c=getchar();
    while(c<‘0‘||c>‘9‘){if(c==‘-‘) f=-1; c=getchar();}
    while(c>=‘0‘&&c<=‘9‘){ans=ans*10+(c-‘0‘); c=getchar();}
    return ans*f;
}
LL ans[M],s[3*M],xs[3*M];
int n,m,xp,qp,ep;
int lowbit(int x){return x&-x;}
void add(int x,LL v){
    while(x<=xp){
        s[x]+=v;
        x+=lowbit(x);
    }
}
LL query(int x){
    LL ans=0;
    while(x){
        ans+=s[x];
        x-=lowbit(x);
    }
    return ans;
}
struct Q{
    LL l,r,h,id,s;
    bool operator <(const Q& x)const{return h<x.h;}
    void calc(){
        ans[id]+=(query(r)-query(l-1))*s;
    }
}q[2*M];
struct pos{
    LL x,y,w;
    bool operator <(const pos& h)const{return y<h.y;}
    void calc(){
        add(x,w);
    }
}e[M];
void $(LL &x){x=lower_bound(xs,xs+xp,x)-xs+1;}
int main()
{
    LL x,y,hx,hy;
    n=read(); m=read();
    for(int i=1;i<=n;i++){
        x=read(); y=read(); hx=read();
        e[ep++]=(pos){xs[xp++]=x,y,hx};
    }
    for(int i=1;i<=m;i++){
        x=read(); y=read(); hx=read(); hy=read();
        xs[xp++]=x; xs[xp++]=hx;
        q[qp++]=(Q){x,hx,y-1,i,-1};
        q[qp++]=(Q){x,hx,hy,i,1};
    }
    sort(xs,xs+xp);
    for(int i=0;i<ep;i++) $(e[i].x);
    for(int i=0;i<qp;i++) $(q[i].l),$(q[i].r);
    sort(e,e+ep);
    sort(q,q+qp);
    for(int i=0,j=0;i<qp;i++){
        while(j<ep&&e[j].y<=q[i].h) e[j++].calc();
        q[i].calc();
    }
    for(int i=1;i<=m;i++) printf("%lld\n",ans[i]);
    return 0;
}