#include<bits/stdc++.h>
#define maxn 1024
using namespace std;
typedef long long ll;
int n,k,m,v[10025][10025];
inline const void read(int &a)
{
a=0;
char c=getchar();
while(c>'9'||c<'0') c=getchar();
while(c>='0'&&c<='9')
{
a=(a<<1)+(a<<3)+c-'0';
c=getchar();
}
}
void add(int x,int y,ll c)
{
while(x<=maxn)
{
int y1=y;
while(y1<=maxn)
{
v[x][y1]+=c;
y1+=(y1&-y1);
}
x+=(x&-x);
}
}
ll sum(int x,int y)
{
ll ans=0;
while(x)
{
int y1=y;
while(y1)
{
ans+=v[x][y1];
y1-=(y1&-y1);
}
x-=(x&-x);
}
return ans;
}
int main()
{
memset(v,0,sizeof(v));
int T,x,y;
read(n);read(m);
for(int i=1;i<=n;i++)
{
read(x);read(y);read(k);
add(x+1,y+1,k);
}
for(int i=1;i<=m;i++)
{
int x1,x2,y1,y2;
read(x1);read(y1);read(x2);read(y2);
ll ans1=sum(x1,y1),ans2=sum(x2+1,y2+1),ans3=sum(x1,y2+1),ans4=sum(x2+1,y1);
ll ans=ans2+ans1-ans3-ans4;
cout<<ans<<endl;
}
return 0;
}