#include <map>
#include <set>
#include <cassert>
#include <cstdio>
#include <vector>
#include <cstring>
using namespace std;

typedef pair<int,int> PII;

const int N = 100005;

int n, m, f[N];
vector<int> e[N];
map<int,int> add[N];

class ChainSplit {
public:
    static const int SIZE = 100005;
    int sz[SIZE],lv[SIZE];
    int rt[SIZE],fa[SIZE];
    int cnt,seg[SIZE],idx[SIZE],low[SIZE],top[SIZE],len[SIZE];
    int init(int n, const vector<int> e[]){
        memset(len,cnt=0,sizeof(len));
        memset(lv,0,sizeof(lv));
        for(int i=0;i<n;i++) if(!lv[i]){
            split(rt[i]=fa[i]=i,e);
            top[seg[i]]=fa[i]=SIZE-1;
        }
        return cnt;
    }
    int lca(int x, int y){
        if(rt[x]!=rt[y]) return -1;
        while(seg[x]!=seg[y]){
            int p=top[seg[x]],q=top[seg[y]];
            if(lv[p]>lv[q]) x=p; else y=q;
        }
        return lv[x]<lv[y]?x:y;
    }
    void insert(int x, int y, int z) {
        if (lv[x] < lv[y]) swap(x, y);
        int p = lca(x, y);
        if (p == y) modify(x, y, z, +1);
        else {
            if (p == x) while(1);
            modify(x, p, z, +1);
            modify(y, p, z, +1);
            modify(p, p, z, -1);
        }
    }
    void gao() {
        for (int i = 0; i < cnt; ++i) {
            map<int,int> sum;
            set<PII> st;
            st.insert(PII(0, 0));
            for (int x = low[i]; x != top[i]; x = fa[x]) {
                map<int,int>::iterator it = add[x].begin();
                for (; it != add[x].end(); ++it) {
                    int z = it->first;
                    int w = it->second;
                    int& c = sum[z];
                    st.erase(PII(-c, z));
                    c += w;
                    st.insert(PII(-c, z));
                }
                f[x] = st.begin()->second;
            }
        }
    }
private:
    void modify(int x, int y, int z, int w) {
        while (seg[x] != seg[y]) {
            if (lv[x] < lv[y]) while(1);
            add[x][z] += w;
            x = top[seg[x]];
        }
        if (lv[x] < lv[y]) while(1);
        add[x][z] += w;
        if (fa[y] != top[seg[y]]) add[fa[y]][z] -= w;
    }
    void split(int x, const vector<int> e[]){
        int y,t=-1;
        sz[x]=1;
        rt[x]=rt[fa[x]];
        lv[x]=lv[fa[x]]+1;
        for(size_t i=0;i<e[x].size();i++) if(e[x][i]!=fa[x]){
            fa[y=e[x][i]]=x;
            split(y,e);
            sz[x]+=sz[y];
            if(t<0 || sz[y]>sz[t]) t=y;
        }
        seg[x]=~t?seg[t]:cnt;
        idx[x]=~t?idx[t]+1:0;
        if(t<0) low[cnt++]=x;
        len[seg[x]]++;
        top[seg[x]]=fa[x];
    }
} tr;

int main() {
    while (2 == scanf("%d%d", &n, &m) && n) {
        for (int i = 0; i < n; ++i) {
            e[i].clear();
            add[i].clear();
        }
        for (int x, y, i = 1; i < n; ++i) {
            scanf("%d%d", &x, &y);
            --x, --y;
            e[x].push_back(y);
            e[y].push_back(x);
        }
        tr.init(n, e);
        for (int x, y, z, i = 0; i < m; ++i) {
            scanf("%d%d%d", &x, &y, &z);
            --x, --y;
            tr.insert(x, y, z);
        }
        tr.gao();
        for (int i = 0; i < n; ++i) printf("%d\n", f[i]);
    }
}
