/+ dub.sdl:
    name "B"
    dependency "dcomp" version=">=0.6.0"
+/

import std.stdio, std.algorithm, std.range, std.conv;
// import dcomp.scanner;

// import dcomp.graph.dijkstra;

struct State {
    int tm;
    int col;
    int opCmp(State r) {
        if (tm < r.tm) return -1;
        if (tm > r.tm) return 1;
        return 0;
    }
}


int main() {
    auto sc = new Scanner(stdin);
    int n, m;
    sc.read(n, m);
    int[][] g = new int[][](n);
    State[][] dp = new State[][](12, n);
    dp.each!(v => v[] = State(0, 0));
    foreach (i; 0..m) {
        int a, b;
        sc.read(a, b); a--; b--;
        g[a] ~= b;
        g[b] ~= a;
    }
    int q;
    sc.read(q);
    foreach (i; 0..q) {
        int v, d, c;
        sc.read(v, d, c); v--;
        dp[d][v] = State(i+1, c);
    }
    foreach_reverse (ph; 0..11) {
        foreach (i; 0..n) {
            dp[ph][i] = max(dp[ph][i], dp[ph+1][i]);
            foreach (j; g[i]) {
                dp[ph][i] = max(dp[ph][i], dp[ph+1][j]);
            }
        }
    }

    foreach (i; 0..n) {
        writeln(dp[0][i].col);
    }
    return 0;
}
/* IMPORT /home/yosupo/Program/dcomp/source/dcomp/scanner.d */
// module dcomp.scanner;

class Scanner {
    import std.stdio : File;
    import std.conv : to;
    import std.range : front, popFront, array, ElementType;
    import std.array : split;
    import std.traits : isSomeChar, isStaticArray, isArray; 
    import std.algorithm : map;
    File f;
    this(File f) {
        this.f = f;
    }
    char[512] lineBuf;
    char[] line;
    private bool succ() {
        import std.range.primitives : empty, front, popFront;
        import std.ascii : isWhite;
        while (true) {
            while (!line.empty && line.front.isWhite) {
                line.popFront;
            }
            if (!line.empty) break;
            if (f.eof) return false;
            line = lineBuf[];
            f.readln(line);
        }
        return true;
    }

    private bool readSingle(T)(ref T x) {
        import std.algorithm : findSplitBefore;
        import std.string : strip;
        import std.conv : parse;
        if (!succ()) return false;
        static if (isArray!T) {
            alias E = ElementType!T;
            static if (isSomeChar!E) {
                //string or char[10] etc
                //todo optimize
                auto r = line.findSplitBefore(" ");
                x = r[0].strip.dup;
                line = r[1];
            } else {
                auto buf = line.split.map!(to!E).array;
                static if (isStaticArray!T) {
                    //static
                    assert(buf.length == T.length);
                }
                x = buf;
                line.length = 0;
            }
        } else {
            x = line.parse!T;
        }
        return true;
    }
    int read(T, Args...)(ref T x, auto ref Args args) {
        if (!readSingle(x)) return 0;
        static if (args.length == 0) {
            return 1;
        } else {
            return 1 + read(args);
        }
    }
}



unittest {
    import std.path : buildPath;
    import std.file : tempDir;
    import std.algorithm : equal;
    import std.stdio : File;
    string fileName = buildPath(tempDir, "kyuridenanmaida.txt");
    auto fout = File(fileName, "w");
    fout.writeln("1 2 3");
    fout.writeln("ab cde");
    fout.writeln("1.0 1.0 2.0");
    fout.close;
    Scanner sc = new Scanner(File(fileName, "r"));
    int a;
    int[2] b;
    char[2] c;
    string d;
    double e;
    double[] f;
    sc.read(a, b, c, d, e, f);
    assert(a == 1);
    assert(equal(b[], [2, 3]));
    assert(equal(c[], "ab"));
    assert(equal(d, "cde"));
    assert(e == 1.0);
    assert(equal(f, [1.0, 2.0]));
}

unittest {
    import std.path : buildPath;
    import std.file : tempDir;
    import std.algorithm : equal;
    import std.stdio : File, writeln;
    import std.datetime;
    string fileName = buildPath(tempDir, "kyuridenanmaida.txt");
    auto fout = File(fileName, "w");
    foreach (i; 0..1_000_000) {
        fout.writeln(3*i, " ", 3*i+1, " ", 3*i+2);
    }
    fout.close;
    writeln("Scanner Speed Test(3*1,000,000 int)");
    StopWatch sw;
    sw.start;
    Scanner sc = new Scanner(File(fileName, "r"));
    foreach (i; 0..500_000) {
        int a, b, c;
        sc.read(a, b, c);
        assert(a == 3*i);
        assert(b == 3*i+1);
        assert(c == 3*i+2);
    }
    foreach (i; 500_000..700_000) {
        int[3] d;
        sc.read(d);
        int a = d[0], b = d[1], c = d[2];
        assert(a == 3*i);
        assert(b == 3*i+1);
        assert(c == 3*i+2);
    }
    foreach (i; 700_000..1_000_000) {
        int[] d;
        sc.read(d);
        assert(d.length == 3);
        int a = d[0], b = d[1], c = d[2];
        assert(a == 3*i);
        assert(b == 3*i+1);
        assert(c == 3*i+2);
    }
    writeln(sw.peek.msecs, "ms");
}
/* IMPORT /home/yosupo/Program/dcomp/source/dcomp/algorithm.d */
// module dcomp.algorithm;

import std.range.primitives;
import std.traits : isFloatingPoint, isIntegral;

//[0,0,0,...,1,1,1]で、初めて1となる場所を探す。pred(l) == 0, pred(r) == 1と仮定
T binSearch(alias pred, T)(T l, T r) if (isIntegral!T) {
    while (r-l > 1) {
        T md = (l+r)/2;
        if (!pred(md)) l = md;
        else r = md;
    }
    return r;
}

T binSearch(alias pred, T)(T l, T r, int cnt = 60) if (isFloatingPoint!T) {
    foreach (i; 0..cnt) {
        T md = (l+r)/2;
        if (!pred(md)) l = md;
        else r = md;
    }
    return r;
}

Rotator!Range rotator(Range)(Range r) {
    return Rotator!Range(r);
}

struct Rotator(Range)
if (isForwardRange!Range && hasLength!Range) {
    size_t cnt;
    Range start, now;
    this(Range r) {
        cnt = 0;
        start = r.save;
        now = r.save;
    }
    this(this) {
        start = start.save;
        now = now.save;
    }
    @property bool empty() {
        return now.empty;
    }
    @property auto front() {
        assert(!now.empty);
        import std.range : take, chain;
        return chain(now, start.take(cnt));
    }
    @property Rotator!Range save() {
        return this;
    }
    void popFront() {
        cnt++;
        now.popFront;
    }
}


E minimum(alias pred = "a < b", Range, E = ElementType!Range)(Range range, E seed)
if (isInputRange!Range && !isInfinite!Range) {
    import std.algorithm, std.functional;
    return reduce!((a, b) => binaryFun!pred(a, b) ? a : b)(seed, range);
}

ElementType!Range minimum(alias pred = "a < b", Range)(Range range) {
    assert(!range.empty, "range must not empty");
    auto e = range.front; range.popFront;
    return minimum!pred(range, e);
}

E maximum(alias pred = "a < b", Range, E = ElementType!Range)(Range range, E seed)
if (isInputRange!Range && !isInfinite!Range) {
    import std.algorithm, std.functional;
    return reduce!((a, b) => binaryFun!pred(a, b) ? b : a)(seed, range);
}

ElementType!Range maximum(alias pred = "a < b", Range)(Range range) {
    assert(!range.empty, "range must not empty");
    auto e = range.front; range.popFront;
    return maximum!pred(range, e);
}

unittest {
    assert(minimum([2, 1, 3]) == 1);
    assert(minimum!"a > b"([2, 1, 3]) == 3);
    assert(minimum([2, 1, 3], -1) == -1);
    assert(minimum!"a > b"([2, 1, 3], 100) == 100);

    assert(maximum([2, 1, 3]) == 3);
    assert(maximum!"a > b"([2, 1, 3]) == 1);
    assert(maximum([2, 1, 3], 100) == 100);
    assert(maximum!"a > b"([2, 1, 3], -1) == -1);
}

bool[ElementType!Range] toMap(Range)(Range r) {
    import std.algorithm : each;
    bool[ElementType!Range] res;
    r.each!(a => res[a] = true);
    return res;
}
/* IMPORT /home/yosupo/Program/dcomp/source/dcomp/graph/dijkstra.d */
// module dcomp.graph.djikstra;

// import dcomp.algorithm;

struct Dijkstra(T) {
    T[] dist;
    int[] from;
    this(int n, T inf) {
        dist = new T[n]; dist[] = inf;
        from = new int[n];
    }
}

Dijkstra!D dijkstra(D, T)(T g, int s, D inf = D.max) {
    import std.conv : to;
    import std.typecons : Tuple;
    import std.container : make, Array, heapify;

    int V = g.length.to!int;
    auto dijk = Dijkstra!D(V, inf);
    with (dijk) {        
        alias P = Tuple!(int, "to", D, "dist");
        auto q = heapify!"a.dist>b.dist"(make!(Array!P)([P(s, D(0))]));

        dist[s] = D(0);
        from[s] = -1;
        while (!q.empty) {
            P p = q.front; q.popFront();
            if (dist[p.to] < p.dist) continue;
            foreach (e; g[p.to]) {
                if (p.dist+e.dist < dist[e.to]) {
                    dist[e.to] = p.dist+e.dist;
                    from[e.to] = p.to;
                    q.insert(P(e.to, dist[e.to]));
                }
            }
        }
    }
    return dijk;
}

Dijkstra!D dijkstraDense(D, T)(T g, int s, D inf = D.max) {
    import std.conv : to;
    import std.typecons : Tuple;
    import std.container : make, Array, heapify;
    import std.range : enumerate;
    import std.algorithm : filter;

    int V = g.length.to!int;
    auto dijk = Dijkstra!D(V, inf);
    with (dijk) {
        alias P = Tuple!(int, "to", D, "dist");

        bool[] used = new bool[](V);
        dist[s] = D(0);
        from[s] = -1;
        while (true) {
            //todo can optimize
            auto rng = dist.enumerate.filter!(a => !used[a.index]);
            if (rng.empty) break;
            auto nx = rng.minimum!"a.value < b.value";
            used[nx.index] = true;
            P p = P(nx.index.to!int, nx.value); 
            if (dist[p.to] < p.dist) continue;
            foreach (e; g[p.to]) {
                if (p.dist+e.dist < dist[e.to]) {
                    dist[e.to] = p.dist+e.dist;
                    from[e.to] = p.to;
                }
            }
        }
    }
    return dijk;
}

unittest {
    import std.algorithm, std.conv, std.stdio, std.range;
    import std.random;
    import std.typecons;
    import std.datetime;

    alias E = Tuple!(int, "to", int, "dist");

    writeln("Dijkstra Random100000");
    void f(alias pred)() {
        int n = uniform(1, 100);
        int m = uniform(1, 1000);
        E[][] g = new E[][n];
        int[][] dist = new int[][](n, n);
        foreach (i, ref v; dist) {
            v[] = 10^^9;
        }
        iota(n).each!(i => dist[i][i] = 0);
        foreach (i; 0..m) {
            int a = uniform(0, n);
            int b = uniform(0, n);
            int c = uniform(0, 1000);
            g[a] ~= E(b, c);
            dist[a][b] = min(dist[a][b], c);
        }
        foreach (k; 0..n) {
            foreach (i; 0..n) {
                foreach (j; 0..n) {
                    dist[i][j] = min(dist[i][j], dist[i][k]+dist[k][j]);
                }
            }
        }
        foreach (i; 0..n) {
            auto dijk = pred!int(g, i, 10^^9);
            foreach (j; 0..n) {
                assert(dist[i][j] == dijk.dist[j]);
            }
            assert(dijk.from[i] == -1);
            foreach (j; 0..n) {
                if (i == j) continue;
                if (dist[i][j] == 10^^9) continue;
                int b = dijk.from[j];
                assert(dijk.dist[j] == dist[i][b]+dist[b][j]);
            }
        }
    }
    auto ti = benchmark!(f!dijkstra, f!dijkstraDense)(100);
    writeln(ti[0].msecs, "ms");
    writeln(ti[1].msecs, "ms");
}
