#include <cstdio>
#include <algorithm>
using namespace std;
char buf[10000000], *ptr = buf - 1;
inline int readint(){
int f = 1, n = 0;
char ch = *++ptr;
while(ch < ‘0‘ || ch > ‘9‘){
if(ch == ‘-‘) f = -1;
ch = *++ptr;
}
while(ch <= ‘9‘ && ch >= ‘0‘){
n = (n << 1) + (n << 3) + ch - ‘0‘;
ch = *++ptr;
}
return f * n;
}
typedef long long ll;
const int maxn = 100000 + 10, maxm = 100000 + 10;
int numy[maxn], ycnt;
ll arr[maxn] = {0};
inline void Update(int w, int val){
for(; w <= ycnt; w += w & -w)
arr[w] += val;
}
inline ll Query(int w){
ll s = 0;
for(; w; w -= w & -w)
s += arr[w];
return s;
}
struct Node{
int x, y, p;
Node(){}
bool operator < (const Node &rhs) const {
return x < rhs.x;
}
}no[maxn];
struct Que{
int x, y, id, type;
Que(){}
Que(int _x, int _y, int _i, int _t): x(_x), y(_y), id(_i), type(_t){}
bool operator < (const Que &rhs) const {
return x < rhs.x;
}
}q[maxm * 4];
ll ans[maxm] = {0};
int main(){
fread(buf, sizeof(char), sizeof(buf), stdin);
int n, m;
n = readint();
m = readint();
for(int x, y, p, i = 1; i <= n; i++){
no[i].x = readint();
numy[i] = no[i].y = readint();
no[i].p = readint();
}
sort(no + 1, no + n + 1);
sort(numy + 1, numy + n + 1);
ycnt = unique(numy + 1, numy + n + 1) - (numy + 1);
for(int i = 1; i <= n; i++) no[i].y = lower_bound(numy + 1, numy + ycnt + 1, no[i].y) - numy;
for(int x1, y1, x2, y2, i = 1; i <= m; i++){
x1 = readint();
y1 = lower_bound(numy + 1, numy + ycnt + 1, readint()) - numy;
x2 = readint();
y2 = upper_bound(numy + 1, numy + ycnt + 1, readint()) - numy - 1;
q[i] = Que(x2, y2, i, 1);
q[i + m] = Que(x1 - 1, y1 - 1, i, 1);
q[i + 2 * m] = Que(x1 - 1, y2, i, 2);
q[i + 3 * m] = Que(x2, y1 - 1, i, 2);
}
sort(q + 1, q + 4 * m + 1);
int aa = 1, bb = 1;
while(aa <= n && bb <= 4 * m){
if(no[aa].x <= q[bb].x){
Update(no[aa].y, no[aa].p);
aa++;
}
else{
if(q[bb].type == 1) ans[q[bb].id] += Query(q[bb].y);
else ans[q[bb].id] -= Query(q[bb].y);
bb++;
}
}
while(bb <= 4 * m){
if(q[bb].type == 1) ans[q[bb].id] += Query(q[bb].y);
else ans[q[bb].id] -= Query(q[bb].y);
bb++;
}
for(int i = 1; i <= m; i++)
printf("%lld\n", ans[i]);
return 0;
}