#include <cstdio>
#include <algorithm>
#define Rep( i , _begin , _end ) for(int i=(_begin),i##_END=(_end);i<=(i##_END);i++)
#define For( i , _begin , _end ) for(int i=(_begin),i##_END=(_end);i!=(i##_END);i++)
#define Lop( i , _begin , _end ) for(int i=(_begin),i##_END=(_end);i>=(i##_END);i--)
#define Dnt( i , _begin , _end ) for(int i=(_begin),i##_END=(_end);i!=(i##_END);i--)
using std :: max;
using std :: min;
typedef long long LL;
const int maxx = 800000 + 25;
int n,m,x,y,z,cnt,tot,x1,x2,y1,y2,num,lx,ly;
int a[maxx],b[maxx],val[maxx],u[maxx],v[maxx];
LL T[maxx],ans[maxx];
struct Node{
int x,y;
int f,id;
int v;
}A[maxx];
namespace Zyerstream{
const int L = 1<<15;
char buffer[L],*_,*__;
inline char Getchar(){
if(_ == __) __ = (_ = buffer) + fread(buffer,1,L,stdin);
return _ == __? EOF : *_ ++;
}
template <class T> inline void read(T &in){
int f = 1;char __;
for(__ = Getchar();__ > '9' || __ < '0';__ = Getchar()) if(__ == '-') f = -1;
for(in = 0;__ >= '0' && __ <= '9';__ = Getchar()) in = (in<<1) + (in<<3) + __ - '0';
in *= f;
}
}
namespace init{
using namespace Zyerstream;
bool cmp(Node a,Node b){
return a.x == b.x? a.id < b.id : a.x < b.x;
}
int main(){
scanf("%d%d",&n,&m);
Rep( i , 1 , n ) read(x),read(y),read(z),a[++cnt] = x,b[cnt] = y,val[cnt] = z,u[cnt] = a[cnt],v[cnt] = b[cnt];
Rep( i , 1 , m ){
read(x1);read(y1);read(x2);read(y2);
a[++cnt] = x1;b[cnt] = y1;u[cnt] = a[cnt];v[cnt] = b[cnt];
a[++cnt] = x2;b[cnt] = y2;u[cnt] = a[cnt];v[cnt] = b[cnt];
}
std :: sort(u+1,u+cnt+1);
std :: sort(v+1,v+cnt+1);
lx = std :: unique(u+1,u+cnt+1) - u - 1;
ly = std :: unique(v+1,v+cnt+1) - v - 1;
Rep( i , 1 , n ){
++tot;
x = std :: lower_bound(u+1,u+lx+1,a[tot]) - u;
y = std :: lower_bound(v+1,v+ly+1,b[tot]) - v;
A[tot].x = x;A[tot].y = y;A[tot].v = val[tot];
}
num = n;
Rep( i , 1 , m ){
++num;
x1 = std :: lower_bound(u+1,u+lx+1,a[num]) - u;
y1 = std :: lower_bound(v+1,v+ly+1,b[num]) - v;
++num;
x2 = std :: lower_bound(u+1,u+lx+1,a[num]) - u;
y2 = std :: lower_bound(v+1,v+ly+1,b[num]) - v;
A[++tot].x = x1-1;A[tot].y = y1-1;A[tot].f = 1;A[tot].id = i;
A[++tot].x = x1-1;A[tot].y = y2;A[tot].f = -1;A[tot].id = i;
A[++tot].x = x2;A[tot].y = y1-1;A[tot].f = -1;A[tot].id = i;
A[++tot].x = x2;A[tot].y = y2;A[tot].f = 1;A[tot].id = i;
}
std :: sort(A+1,A+tot+1,cmp);
}
}
namespace Bit{
void Add(int x,int k){
for(int i=x;i<=maxx;i+=i&(-i))
T[i] += k;
}
LL Query(int x){
LL ans = 0;
for(int i=x;i;i-=i&(-i))
ans += T[i];
return ans;
}
}
using namespace Bit;
int main(){
init :: main();
Rep( i , 1 , tot ){
if(!A[i].id) Add(A[i].y,A[i].v);
else ans[A[i].id] += Query(A[i].y)*A[i].f;
}
Rep( i , 1 , m ) printf("%lld\n",ans[i]);
return 0;
}