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 N, M, Q;
int[] C;
int[][] adj;
bool[] used;

void dfs(int n, int color, int d, int d_max) {
    if (used[n]) return;
    C[n] = color;
    used[n] = true;
    if (d == d_max) return;
    foreach (m; adj[n]) {
        if (!used[m]) dfs(m, color, d+1, d_max);
    }
}

void main() {
    auto s = readln.split.map!(to!int);
    N = s[0];
    M = s[1];
    adj = new int[][](N);
    C = 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;
    }

    used = new bool[](N);
    Q = readln.chomp.to!int;
    foreach (i; 0..Q) {
        fill(used, false);
        s = readln.split.map!(to!int);
        dfs(s[0]-1, s[2], 0, s[1]);
    }

    C.each!writeln;
}
