n, m = list(map(int, input().split()))



g = [[i] for i in range(n)]



for _ in range(m):

    u, v = [int(x) - 1 for x in input().split()]

    g[u].append(v)

    g[v].append(u)



q = int(eval(input()))

c = [None] * q

dp = [[-1 for j in range(n)] for i in range(11)]

for i in range(q):

    v, d, c[i] = list(map(int, input().split()))

    dp[d][v - 1] = i

 

for i in reversed(list(range(1, 11))):

    dp[i - 1] = [max(dp[i - 1][u], max(dp[i][v] for v in g[u])) for u in range(n)]



for i in range(n):

    if dp[0][i] == -1:

        print('0')

    else:

        print((c[dp[0][i]]))
n, m = list(map(int, input().split()))



g = [[i] for i in range(n)]



for _ in range(m):

    u, v = [int(x) - 1 for x in input().split()]

    g[u].append(v)

    g[v].append(u)



q = eval(input())

c = [None] * q

dp = [[-1 for j in range(n)] for i in range(11)]

for i in range(q):

    v, d, c[i] = list(map(int, input().split()))

    dp[d][v - 1] = i

 

for i in reversed(list(range(1, 11))):

    dp[i - 1] = [max(dp[i - 1][u], max(dp[i][v] for v in g[u])) for u in range(n)]



for i in range(n):

    if dp[0][i] == -1:

        print('0')

    else:

        print((c[dp[0][i]]))
n, m = list(map(int, input().split()))
g = [[i] for i in range(n)]
for _ in range(m):
    u, v = [int(x) - 1 for x in input().split()]
    g[u].append(v)
    g[v].append(u)
q = int(eval(input()))
c = [None] * q
dp = [[-1 for j in range(n)] for i in range(11)]
for i in range(q):
    v, d, c[i] = list(map(int, input().split()))
    dp[d][v - 1] = i
for i in reversed(list(range(1, 11))):
    dp[i - 1] = [max(dp[i - 1][u], max(dp[i][v] for v in g[u])) for u in range(n)]
for i in range(n):
    if dp[0][i] == -1:
        print("0")
    else:
        print((c[dp[0][i]]))

n, m = list(map(int, input().split()))
g = [[i] for i in range(n)]
for _ in range(m):
    u, v = [int(x) - 1 for x in input().split()]
    g[u].append(v)
    g[v].append(u)
q = eval(input())
c = [None] * q
dp = [[-1 for j in range(n)] for i in range(11)]
for i in range(q):
    v, d, c[i] = list(map(int, input().split()))
    dp[d][v - 1] = i
for i in reversed(list(range(1, 11))):
    dp[i - 1] = [max(dp[i - 1][u], max(dp[i][v] for v in g[u])) for u in range(n)]
for i in range(n):
    if dp[0][i] == -1:
        print("0")
    else:
        print((c[dp[0][i]]))

-q = int(eval(input())) +q = eval(input())