import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, core.stdc.string;

alias Tuple!(int, "n", int, "d") Query;
int[] color;
int[] mem;
int[][] adj;

void bfs(int n, int d, int c) {
    DList!Query queue;
    queue.insert(Query(n, d));
    while(!queue.empty) {
        auto t = queue.front;
        queue.removeFront;
        if (t.d < mem[t.n]) continue;
        if (color[t.n] == 0) color[t.n] = c;
        mem[t.n] = t.d;
        if (t.d == 0) continue;
        foreach (m; adj[t.n]) {
            if (t.d - 1 < mem[m]) continue;
            queue.insert(Query(m, t.d-1));
        }
    }
}



void main() {
    auto s = readln.split.map!(to!int);
    auto N = s[0];
    auto M = s[1];
    color = new int[](N);
    mem = new int[](N);
    fill(mem, -1);
    adj = new int[][](N);
    foreach (i; 0..M) {
        s = readln.split.map!(to!int);
        adj[s[0]-1] ~= s[1]-1;
        adj[s[1]-1] ~= s[0]-1;
    }

    auto Q = readln.chomp.to!int;
    auto queries = new int[][](Q);
    foreach (i; 0..Q) {
        queries[i] = readln.split.map!(to!int).array;
    }


    foreach (i; iota(Q-1, -1, -1)) {
        auto v = queries[i][0] - 1;
        auto d = queries[i][1];
        auto c = queries[i][2];
        bfs(v, d, c);
    }

    color.each!writeln;
}
