#include <bits/stdc++.h>
using namespace std;
vector<int> ans;
vector<vector<int> > al;
vector<set<int> > colors;
void dfs(int u) {
for (auto &v: al[u]) {
dfs(v);
if (colors[v].size() > colors[u].size()) {
swap(colors[u], colors[v]);
}
for (auto &c: colors[v]) {
colors[u].insert(c);
}
colors[v].clear();
}
ans[u] = (int) colors[u].size();
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr), cout.tie(nullptr);
int n, m;
cin >> n >> m;
ans.assign(n + 1, 0);
al.assign(n + 1, vector<int>());
colors.assign(n + 1, set<int>());
vector<array<int, 4> > rect(n + 1);
vector<array<int, 3> > events;
for (int i = 1; i <= n; i++) {
cin >> rect[i][0] >> rect[i][1] >> rect[i][2] >> rect[i][3];
events.push_back({rect[i][0], 1, i});
events.push_back({rect[i][2], 3, i});
}
vector<array<int, 3> > ball(m + 1);
for (int i = 1; i <= m; i++) {
cin >> ball[i][0] >> ball[i][1] >> ball[i][2];
events.push_back({ball[i][0], 2, i});
}
sort(events.begin(), events.end());
vector<int> par(n + 1);
set<array<int, 3> > active; // y, type, id
for (auto &[x, type, id]: events) {
if (type == 1) {
auto it = active.lower_bound({rect[id][1], -1, -1});
if (it != active.end()) {
if ((*it)[1] == 3) {
par[id] = (*it)[2];
} else {
par[id] = par[(*it)[2]];
}
}
al[par[id]].push_back(id);
active.insert({rect[id][1], 1, id});
active.insert({rect[id][3], 3, id});
} else if (type == 2) {
auto it = active.lower_bound({ball[id][1], -1, -1});
if (it != active.end()) {
if ((*it)[0] == ball[id][1] || (*it)[1] == 3) {
colors[(*it)[2]].insert(ball[id][2]);
} else {
colors[par[(*it)[2]]].insert(ball[id][2]);
}
}
} else {
active.erase({rect[id][1], 1, id});
active.erase({rect[id][3], 3, id});
}
}
dfs(0);
for (int i = 1; i <= n; i++) {
cout << ans[i] << '\n';
}
return 0;
}