import sys



readline = sys.stdin.readline



ns = lambda: readline().rstrip()

ni = lambda: int(readline().rstrip())

nm = lambda: map(int, readline().split())

nl = lambda: list(map(int, readline().split()))



def solve():

  n, m = nm()

  G = [list() for _ in range(n)]

  for _ in range(m):

    a, b = nm()

    a -= 1; b -= 1

    G[a].append(b)

    G[b].append(a)

  Q = int(input())

  queries = [tuple(nm()) for _ in range(Q)][::-1]

  dp = [[Q]*11 for _ in range(n)]

  for i in range(Q-1, -1, -1):

    v, d, _ = queries[i]

    dp[v-1][d] = i

    

  for d in range(10, 0, -1):

    for v in range(n):

      for x in G[v] + [v]:

        if dp[x][d-1] > dp[v][d]:

          dp[x][d-1] = dp[v][d]

          

  queries.append((-1, -1, 0))

  color = [queries[dp[v][0]][2] for v in range(n)]

  print(*color, sep='\n')

  return



solve()

import sys

from collections import deque



readline = sys.stdin.readline



ns = lambda: readline().rstrip()

ni = lambda: int(readline().rstrip())

nm = lambda: map(int, readline().split())

nl = lambda: list(map(int, readline().split()))



def solve():

  n, m = nm()

  G = [list() for _ in range(n)]

  for _ in range(m):

    a, b = nm()

    a -= 1; b -= 1

    G[a].append(b)

    G[b].append(a)

  Q = int(input())

  color = [0]*n

  dist = [-1]*n

  queries = [tuple(nm()) for _ in range(Q)][::-1]

  for v, d, c in queries:

    v -= 1

    q = deque()

    q.append((v, d))

    while q:

      v, d = q.popleft()

      if dist[v] >= d:

        continue

      dist[v] = d

      if not color[v]: color[v] = c

      for x in G[v]:

        if d - 1 > dist[x]:

          q.append((x, d-1))

  print(*color, sep='\n')

  return



solve()

import sys

readline = sys.stdin.readline
ns = lambda: readline().rstrip()
ni = lambda: int(readline().rstrip())
nm = lambda: map(int, readline().split())
nl = lambda: list(map(int, readline().split()))


def solve():
    n, m = nm()
    G = [list() for _ in range(n)]
    for _ in range(m):
        a, b = nm()
        a -= 1
        b -= 1
        G[a].append(b)
        G[b].append(a)
    Q = int(input())
    queries = [tuple(nm()) for _ in range(Q)][::-1]
    dp = [[Q] * 11 for _ in range(n)]
    for i in range(Q - 1, -1, -1):
        v, d, _ = queries[i]
        dp[v - 1][d] = i
    for d in range(10, 0, -1):
        for v in range(n):
            for x in G[v] + [v]:
                if dp[x][d - 1] > dp[v][d]:
                    dp[x][d - 1] = dp[v][d]
    queries.append((-1, -1, 0))
    color = [queries[dp[v][0]][2] for v in range(n)]
    print(*color, sep="\n")
    return


solve()

import sys
from collections import deque

readline = sys.stdin.readline
ns = lambda: readline().rstrip()
ni = lambda: int(readline().rstrip())
nm = lambda: map(int, readline().split())
nl = lambda: list(map(int, readline().split()))


def solve():
    n, m = nm()
    G = [list() for _ in range(n)]
    for _ in range(m):
        a, b = nm()
        a -= 1
        b -= 1
        G[a].append(b)
        G[b].append(a)
    Q = int(input())
    color = [0] * n
    dist = [-1] * n
    queries = [tuple(nm()) for _ in range(Q)][::-1]
    for v, d, c in queries:
        v -= 1
        q = deque()
        q.append((v, d))
        while q:
            v, d = q.popleft()
            if dist[v] >= d:
                continue
            dist[v] = d
            if not color[v]:
                color[v] = c
            for x in G[v]:
                if d - 1 > dist[x]:
                    q.append((x, d - 1))
    print(*color, sep="\n")
    return


solve()

+from collections import deque +    color = [0] * n +    dist = [-1] * n -    dp = [[Q] * 11 for _ in range(n)] -    for i in range(Q - 1, -1, -1): -        v, d, _ = queries[i] -        dp[v - 1][d] = i -    for d in range(10, 0, -1): -        for v in range(n): -            for x in G[v] + [v]: -                if dp[x][d - 1] > dp[v][d]: -                    dp[x][d - 1] = dp[v][d] -    queries.append((-1, -1, 0)) -    color = [queries[dp[v][0]][2] for v in range(n)] +    for v, d, c in queries: +        v -= 1 +        q = deque() +        q.append((v, d)) +        while q: +            v, d = q.popleft() +            if dist[v] >= d: +                continue +            dist[v] = d +            if not color[v]: +                color[v] = c +            for x in G[v]: +                if d - 1 > dist[x]: +                    q.append((x, d - 1))