#include<bits/stdc++.h>

using namespace std;

int N, M, Q, col[100009], lst[11][100009];
vector < int > h[100009];

int main ()
{
//freopen ("input", "r", stdin);
//freopen ("output", "w", stdout);

scanf ("%d %d", &N, &M);
while (M --)
{
    int x, y;
    scanf ("%d %d", &x, &y);
    h[x].push_back (y);
    h[y].push_back (x);
}
scanf ("%d", &Q);
for (int i=1; i<=Q; i++)
{
    int x, d;
    scanf ("%d %d %d", &x, &d, &col[i]);
    lst[d][x] = i;
}
for (int lev=10; lev>=1; lev--)
    for (int u=1; u<=N; u++)
        if (lst[lev][u] > 0)
            for (auto v : h[u])
                if (lst[lev][u] > lst[lev - 1][v])
                    lst[lev - 1][v] = lst[lev][u];
for (int i=1; i<=N; i++)
{
    int latest = 0;
    for (int j=0; j<=10; j++)
        if (lst[j][i] > latest)
            latest = lst[j][i];
    printf ("%d\n", col[latest]);
}
return 0;
}
