import std.algorithm;
import std.array;
import std.ascii;
import std.container;
import std.conv;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.typecons;
void log(A...)(A arg) { stderr.writeln(arg); }
int size(T)(in T s) { return cast(int)s.length; }

void main() {
    int N, M; readf("%s %s\n", &N, &M);
    auto G = new int[][N];
    foreach (i; 0 .. M) {
        int a, b; readf("%d %d\n", &a, &b);
        a--; b--;
        G[a] ~= b;
        G[b] ~= a;
    }
    int Q; readf("%s\n", &Q);
    auto V = new int[Q];
    auto D = new int[Q];
    auto C = new int[Q];
    foreach (q; 0 .. Q) {
        readf("%s %s %s\n", &V[q], &D[q], &C[q]);
        V[q]--;
    }
    reverse(V); reverse(D); reverse(C);

    auto color = new int[N]; color[] = -1;
    auto max_d = new int[N]; max_d[] = -1;
    void f(int v, int d, int c) {
        if (color[v] < 0) {
            color[v] = c;
        }
        if (max_d[v] >= d) {
            return;
        }
        max_d[v] = d;
        if (d == 0) return;
        foreach (u; G[v]) {
            f(u, d - 1, c);
        }
    }
    foreach (q; 0 .. Q) {
        f(V[q], D[q], C[q]);
    }

    foreach (v; 0 .. N) {
        writeln(max(0, color[v]));
    }
}
