import sys

sys.setrecursionlimit(10**7)



def main():

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

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

  for _ in range(m):

    a, b = list(map(int, input().split()))

    a -= 1

    b -= 1

    G[a].append(b)

    G[b].append(a)

  q = int(eval(input()))

  vdc = [list(map(int, input().split())) for _ in range(q)][::-1]

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

  def dfs(v, d, c):

    if dp[v][d]:

      return dp[v][d]

    if d == 0:

      dp[v][d] = c

      return

    for u in G[v]:

      dfs(u, d-1, c)

    dfs(v, d-1, c)

    dp[v][d] = c

  for v, d, c in vdc:

    dfs(v-1, d, c)

  for i in range(n):

    print((dp[i][0]))

if __name__ == "__main__":

  main()
import sys

sys.setrecursionlimit(10**7)

input = sys.stdin.readline



def main():

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

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

  for _ in range(m):

    a, b = list(map(int, input().split()))

    a -= 1

    b -= 1

    G[a].append(b)

    G[b].append(a)

  q = int(eval(input()))

  vdc = [list(map(int, input().split())) for _ in range(q)][::-1]

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

  def dfs(v, d, c):

    if dp[v][d]:

      return dp[v][d]

    if d == 0:

      dp[v][d] = c

      return

    for u in G[v]:

      dfs(u, d-1, c)

    dfs(v, d-1, c)

    dp[v][d] = c

  for v, d, c in vdc:

    dfs(v-1, d, c)

  for i in range(n):

    print((dp[i][0]))

if __name__ == "__main__":

  main()
import sys

sys.setrecursionlimit(10**7)


def main():
    n, m = list(map(int, input().split()))
    G = [[] for _ in range(n)]
    for _ in range(m):
        a, b = list(map(int, input().split()))
        a -= 1
        b -= 1
        G[a].append(b)
        G[b].append(a)
    q = int(eval(input()))
    vdc = [list(map(int, input().split())) for _ in range(q)][::-1]
    dp = [[0] * 11 for _ in range(n)]

    def dfs(v, d, c):
        if dp[v][d]:
            return dp[v][d]
        if d == 0:
            dp[v][d] = c
            return
        for u in G[v]:
            dfs(u, d - 1, c)
        dfs(v, d - 1, c)
        dp[v][d] = c

    for v, d, c in vdc:
        dfs(v - 1, d, c)
    for i in range(n):
        print((dp[i][0]))


if __name__ == "__main__":
    main()

import sys

sys.setrecursionlimit(10**7)
input = sys.stdin.readline


def main():
    n, m = list(map(int, input().split()))
    G = [[] for _ in range(n)]
    for _ in range(m):
        a, b = list(map(int, input().split()))
        a -= 1
        b -= 1
        G[a].append(b)
        G[b].append(a)
    q = int(eval(input()))
    vdc = [list(map(int, input().split())) for _ in range(q)][::-1]
    dp = [[0] * 11 for _ in range(n)]

    def dfs(v, d, c):
        if dp[v][d]:
            return dp[v][d]
        if d == 0:
            dp[v][d] = c
            return
        for u in G[v]:
            dfs(u, d - 1, c)
        dfs(v, d - 1, c)
        dp[v][d] = c

    for v, d, c in vdc:
        dfs(v - 1, d, c)
    for i in range(n):
        print((dp[i][0]))


if __name__ == "__main__":
    main()

+input = sys.stdin.readline