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;

int[] color;
int[] mem;
int[][] adj;

void dfs(int n, int d, int c) {
    if (d < mem[n]) return;
    if (color[n] == 0) color[n] = c;
    mem[n] = d;
    if (d == 0) return;
    foreach (m; adj[n]) {
        dfs(m, d-1, c);
    }
}



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];
        dfs(v, d, c);
    }

    color.each!writeln;
}
