CodeEff/ECCO huggingface dataset:
# Original solution
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda:sys.stdin.readline().rstrip()
from collections import deque
def resolve():
    n,m=map(int,input().split())
    E=[[] for _ in range(n)]
    for _ in range(m):
        u,v=map(int,input().split())
        u-=1; v-=1
        E[u].append(v)
        E[v].append(u)

    q=int(input())
    VDC=[None]*q
    for i in range(q):
        v,d,c=map(int,input().split())
        v-=1
        VDC[i]=(v,d,c)
    VDC.reverse()

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

    for v,d,c in VDC:
        Q=deque([(v,d)])
        dp[v][d]=1
        while(Q):
            v,d=Q.popleft()
            if(d>0):
                Q.append((v,d-1))
                for nv in E[v]:
                    if(dp[nv][d-1]): continue
                    dp[nv][d-1]=1
                    Q.append((nv,d-1))
            if(ans[v]==0):
                ans[v]=c

    print(*ans,sep='\n')
resolve()


# Optimized solution
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda:sys.stdin.readline().rstrip()
from collections import deque
def resolve():
    n,m=map(int,input().split())
    E=[[] for _ in range(n)]
    for _ in range(m):
        u,v=map(int,input().split())
        u-=1; v-=1
        E[u].append(v)
        E[v].append(u)

    q=int(input())
    VDC=[None]*q
    for i in range(q):
        v,d,c=map(int,input().split())
        v-=1
        VDC[i]=(v,d,c)
    VDC.reverse()

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

    for v,d,c in VDC:
        Q=deque([(v,d)])
        dp[v][d]=1
        while(Q):
            v,d=Q.popleft()
            if(d>0):
                if(not dp[v][d-1]):
                    dp[v][d-1]=1
                    Q.append((v,d-1))
                for nv in E[v]:
                    if(dp[nv][d-1]): continue
                    dp[nv][d-1]=1
                    Q.append((nv,d-1))
            if(ans[v]==0):
                ans[v]=c

    print(*ans,sep='\n')
resolve()
# Original solution
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

n,m = list(map(int,readline().split()))
data = list(map(int,read().split()))
ab = data[:2*m]
q = data[2*m]
vdc = data[2*m+1:]

links = [[] for _ in range(n+1)]
it = iter(ab)
for a,b in zip(it,it):
    links[a].append(b)
    links[b].append(a)

ans = [0] * (n+1)
length = [-1] * (n+1)

for i in range(q-1,-1,-1):
    v,d,c = vdc[i*3:i*3+3]
    if( length[v] >= d):
        continue

    stack = [(v,d)]
    while(stack):
        vj,dj = stack.pop()
        if(ans[vj]==0):
            ans[vj] = c
        if(dj > 0):
            for vk in links[vj]:
                if( length[vk] < dj-1):
                    stack.append((vk,dj-1))

print(('\n'.join(map(str,ans[1:]))))

# Optimized solution
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

n,m = list(map(int,readline().split()))
data = list(map(int,read().split()))
ab = data[:2*m]
q = data[2*m]
vdc = data[2*m+1:]

links = [[] for _ in range(n+1)]
it = iter(ab)
for a,b in zip(it,it):
    links[a].append(b)
    links[b].append(a)

ans = [0] * (n+1)
length = [-1] * (n+1)

for i in range(q-1,-1,-1):
    v,d,c = vdc[i*3:i*3+3]
    if( length[v] >= d):
        continue
    length[v] = d

    stack = [(v,d)]
    while(stack):
        vj,dj = stack.pop()
        if(ans[vj]==0):
            ans[vj] = c
        if(dj > 0):
            for vk in links[vj]:
                if( length[vk] < dj-1):
                    stack.append((vk,dj-1))
                    length[vk] = dj-1

print(('\n'.join(map(str,ans[1:]))))
# Original solution
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n,m = list(map(int, input().split()))
from collections import defaultdict
ns = defaultdict(set)
for _ in range(m):
    u,v = list(map(int, input().split()))
    u -= 1
    v -= 1
    ns[u].add(v)
    ns[v].add(u)
dp = [[(-1,0)]*n for _ in range(11)]
q = int(eval(input()))
qs = [None]*q
for i in range(q):
    v,d,c = tuple(map(int, input().split()))
    v -= 1
    qs[i] = (i,v,d,c)
from itertools import product
for i0,i,u in product(list(range(10,-1,-1)), list(range(0,11)), list(range(n))):
# for i0 in range(10, -1, -1):
    if i==0:
        for i,v,d,_ in qs:
            if i0<=d:
                dp[0][v] = (i,d)
    else:
#     for i in range(1,11):
#         for u in range(n):
        if dp[i-1][u][0]>dp[i][u][0]:
            ind0, d0 = dp[i-1][u]
        else:
            ind0, d0 = dp[i][u]
        for v in ns[u]:
            ind,d = dp[i-1][v]
            if ind>ind0 and d>0:# and i0<=i+d:
                ind0, d0 = ind, d-1
        dp[i][u] = (ind0, d0)
#     print(dp[10])
write("\n".join(map(str, ((qs[dp[10][u][0]][3] if dp[10][u][0]>=0 else 0) for u in range(n)))))

# Optimized solution
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")

n,m = list(map(int, input().split()))
from collections import defaultdict
ns = defaultdict(list)
for _ in range(m):
    u,v = list(map(int, input().split()))
    u -= 1
    v -= 1
    ns[u].append(v)
    ns[v].append(u)
    
dp = [[-1]*n for _ in range(11)]
q = int(eval(input()))
qs = [None]*q
for i in range(q):
    v,d,c = tuple(map(int, input().split()))
    v -= 1
    qs[i] = (i,v,d,c)
    dp[d][v] = i
from itertools import product
for i,u in product(list(range(10,0,-1)), list(range(n))):
    if dp[i][u]>=0:
        dp[i-1][u] = max(dp[i-1][u], dp[i][u])
        for v in ns[u]:
            dp[i-1][v] = max(dp[i-1][v], dp[i][u])

write("\n".join(map(str, ((qs[dp[0][u]][3] if dp[0][u]>=0 else 0) for u in range(n)))))
# Original solution
from collections import deque

n, m = map(int, input().split())
G = [list() for _ in range(n)]
for _ in range(m):
  a, b = map(int, input().split())
  a -= 1; b -= 1
  G[a].append(b)
  G[b].append(a)
Q = int(input())
queries = [tuple(map(int, input().split())) for _ in range(Q)][::-1]
dp = [[Q]*11 for _ in range(n)]
for i, (v, d, _) in enumerate(queries):
  if dp[v-1][d] == Q:
    dp[v-1][d] = i
for d in range(10, 0, -1):
  for v in range(n):
    if dp[v][d] < Q:
      dp[v][d-1] = min(dp[v][d-1], dp[v][d])
      for x in G[v]:
        dp[x][d-1] = min(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')


# Optimized solution
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()
# Original solution
from collections import defaultdict

def paint(v, d, c):
    if (v, d) in memo:
        return
    else:
        memo[(v, d)] = True
    if d == 0:
        color[v] = c
    elif d > 0:
        paint(v, d-1, c)
        for nb in graph[v]:
            paint(nb, d-1, c)

memo = {}
N, M = list(map(int, input().split()))
color = [0] * N
graph = defaultdict(set)
for _ in range(M):
    i, j = list(map(int, input().split()))
    graph[i-1].add(j-1)
    graph[j-1].add(i-1)
Q = int(eval(input()))
vdcs = []
for _ in range(Q):
    v, d, c = list(map(int, input().split()))
    vdcs.append((v-1, d, c))
vdcs.reverse()

for v, d, c in vdcs:
    paint(v, d, c)

for c in color:
    print(c)

# Optimized solution
from collections import defaultdict

def paint(v, d, c):
    if color[v] == 0:
        color[v] = c
    if dp[v] >= d or d == 0:
        return
    dp[v] = d
    for nb in graph[v]:
        paint(nb, d-1, c)

N, M = list(map(int, input().split()))
dp = [0] * N
color = [0] * N
graph = defaultdict(set)
for _ in range(M):
    i, j = list(map(int, input().split()))
    graph[i-1].add(j-1)
    graph[j-1].add(i-1)
Q = int(eval(input()))
vdcs = []
for _ in range(Q):
    v, d, c = list(map(int, input().split()))
    vdcs.append((v-1, d, c))
vdcs.reverse()

for v, d, c in vdcs:
    paint(v, d, c)

for c in color:
    print(c)
# Original solution
from collections import deque
from heapq import heappop, heappush

N,M = list(map(int, input().split()))
edge = [[] for _ in range(N)]
for _ in range(M):
    a,b = list(map(int, input().split()))
    edge[a-1].append(b-1)
    edge[b-1].append(a-1)
Q = int(eval(input()))
VDC = [[int(i) for i in input().split()] for _ in range(Q)]
VDC.reverse()

INF = 10 ** 3

color = [-1] * N

def dijkstra(n, d, c):
    dist = [INF] * N
    dist[n] = 0
    que = [(0, n)]

    while que:
        dv, v = heappop(que)
        if dist[v] < dv: continue

        if color[v] < 0: color[v] = c
        if d == dv: continue
        
        for w in edge[v]:
            if dist[w] > dv + 1:
                dist[w] = dv + 1
                heappush(que, (dist[w], w))

def main():
    for v,d,c in VDC:
        dijkstra(v-1, d, c)

    for c in color:
        print((max(c, 0)))

if __name__ == "__main__":
    main()

# Optimized solution
# 写経AC
N,M = map(int, input().split())
edge = [[] for _ in range(N)]
for _ in range(M):
    a,b = map(int, input().split())
    edge[a-1].append(b-1)
    edge[b-1].append(a-1)
Q = int(input())
VDC = [[int(i) for i in input().split()] for _ in range(Q)]

for i in range(Q):
    VDC[i][0] -= 1

color = [0] * N
# dp[v][d]: 頂点vから距離dは塗装済みか
visited = [[False] * 11 for _ in range(N)]

for v,d,c in reversed(VDC):
    if visited[v][d]: # 既に塗装済み
        continue
    if color[v] == 0:
        color[v] = c
    for dist in range(d + 1):
        # 距離d以下は塗装済み
        visited[v][dist] = True
    
    q = [v]
    for t in range(d - 1, -1, -1):
        qq = []
        for v in q:
            for w in edge[v]:
                if visited[w][t]:
                    continue
                for dist in range(t + 1):
                    visited[w][dist] = True
                if color[w] == 0:
                    color[w] = c
                qq.append(w)
        q = qq

print(*color, sep="\n")
# Original solution
import queue
N,M=list(map(int,input().split()))
G=[[] for i in range(N)]
for i in range(M):
    a,b=list(map(int,input().split()))
    G[a-1].append(b-1)
    G[b-1].append(a-1)
Q=int(eval(input()))
v=[0 for i in range(Q)]
d=[0 for i in range(Q)]
c=[0 for i in range(Q)]
for i in range(Q):
    v[-i-1],d[-i-1],c[-i-1]=list(map(int,input().split()));v[-i-1]-=1
q=queue.Queue()
color=[0 for i in range(N)]
dp=[-1 for i in range(N)]
for t in range(Q):
    if dp[v[t]]>=d[t]:
        continue
    dp[v[t]]=d[t]
    q.put((v[t],d[t]))
    while(not(q.empty())):
        vv,dd=q.get()
        if color[vv]==0:
            color[vv]=c[t]
        dd-=1
        for y in G[vv]:
            if dp[y]>=dd:
                continue
            dp[y]=dd
            q.put((y,dd))
for line in color:
    print(line)


# Optimized solution
from collections import deque
N,M=list(map(int,input().split()))
G=[[] for i in range(N)]
for i in range(M):
    a,b=list(map(int,input().split()))
    G[a-1].append(b-1)
    G[b-1].append(a-1)
Q=int(eval(input()))
v=[0 for i in range(Q)]
d=[0 for i in range(Q)]
c=[0 for i in range(Q)]
for i in range(Q):
    v[-i-1],d[-i-1],c[-i-1]=list(map(int,input().split()));v[-i-1]-=1
q=deque()
color=[0 for i in range(N)]
dp=[-1 for i in range(N)]
for t in range(Q):
    if dp[v[t]]>=d[t]:
        continue
    dp[v[t]]=d[t]
    q.append((v[t],d[t]))
    while(q):
        vv,dd=q.popleft()
        if color[vv]==0:
            color[vv]=c[t]
        dd-=1
        for y in G[vv]:
            if dp[y]>=dd:
                continue
            dp[y]=dd
            q.append((y,dd))
for line in color:
    print(line)
# Original solution
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

#A
def A():
    n = I()

    return

#B
def B():
    def dfs(k,d,x,c):
        if not f[x]:
            f[x] = c
        if k == d:
            return
        for y in v[x]:
            dfs(k+1,d,y,c)
    n,m = LI()
    f = [0]*n
    v = [[] for i in range(n)]
    for i in range(m):
        a,b = LI()
        a -= 1
        b -= 1
        v[a].append(b)
        v[b].append(a)
    q = I()
    l = LIR(q)
    l = l[::-1]
    for x,d,c in l:
        x -= 1
        dfs(0,d,x,c)
    for i in f:
        print(i)
    return

#C
def C():
    n = I()

    return

#D
def D():
    n = I()

    return

#E
def E():
    n = I()

    return

#F
def F():
    n = I()

    return

#Solve
if __name__ == "__main__":
    B()


# Optimized solution
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

#A
def A():
    n = I()

    return

#B
def B():
    def dfs(d,x,c):
        if dp[(d,x)] != None:
            return
        dp[(d,x)] = 1
        if d == 0:
            f[x] = c
        else:
            dfs(d-1,x,c)
            for y in v[x]:
                dfs(d-1,y,c)
    n,m = LI()
    f = [0]*n
    v = [[] for i in range(n)]
    for i in range(m):
        a,b = LI()
        a -= 1
        b -= 1
        v[a].append(b)
        v[b].append(a)
    dp = defaultdict(lambda : None)
    q = I()
    l = LIR(q)
    l = l[::-1]
    for x,d,c in l:
        x -= 1
        dfs(d,x,c)
    for i in f:
        print(i)
    return

#C
def C():
    n = I()

    return

#D
def D():
    n = I()

    return

#E
def E():
    n = I()

    return

#F
def F():
    n = I()

    return

#Solve
if __name__ == "__main__":
    B()
# Original solution
import sys
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt, ceil, floor
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache, reduce
from operator import xor
INF = float("inf")
sys.setrecursionlimit(10**7)

# 4近傍（右, 下, 左, 上）
dy = [0, -1, 0, 1]
dx = [1, 0, -1, 0]


def inside(y: int, x: int, H: int, W: int) -> bool: return 0 <= y < H and 0 <= x < W


color, depth, graph = [], [], {}
def func(v, d, c):
    if not color[v]:
        color[v] = c
    if depth[v] >= d or d == 0:
        return

    for u in graph[v]:
        func(u, d - 1, c)


def main():
    global color, depth, graph
    N, M = map(int, input().split())
    graph = [[] for _ in range(N)]
    for _ in range(M):
        a, b = map(int, input().split())
        a -= 1
        b -= 1
        graph[a].append(b)
        graph[b].append(a)

    Q = int(input())
    q = []
    for _ in range(Q):
        v, d, c = map(int, input().split())
        q.append((v - 1, d, c))

    color = [0] * N
    depth = [0] * N
    for i in range(Q - 1, -1, -1):
        func(q[i][0], q[i][1], q[i][2])
    print(*color, sep="\n")

if __name__ == '__main__':
    main()


# Optimized solution
import sys
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt, ceil, floor
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache, reduce
from operator import xor
INF = float("inf")
sys.setrecursionlimit(10**7)

# 4近傍（右, 下, 左, 上）
dy = [0, -1, 0, 1]
dx = [1, 0, -1, 0]


def inside(y: int, x: int, H: int, W: int) -> bool: return 0 <= y < H and 0 <= x < W


color, depth, graph = [], [], {}
def func(v, d, c):
    if not color[v]:
        color[v] = c
    if depth[v] >= d or d == 0:
        return
    depth[v] = d
    for u in graph[v]:
        func(u, d - 1, c)


def main():
    global color, depth, graph
    N, M = map(int, input().split())
    graph = [[] for _ in range(N)]
    for _ in range(M):
        a, b = map(int, input().split())
        a -= 1
        b -= 1
        graph[a].append(b)
        graph[b].append(a)

    Q = int(input())
    q = []
    for _ in range(Q):
        v, d, c = map(int, input().split())
        q.append((v - 1, d, c))

    color = [0] * N
    depth = [0] * N
    for i in range(Q - 1, -1, -1):
        func(q[i][0], q[i][1], q[i][2])
    print(*color, sep="\n")

if __name__ == '__main__':
    main()
# Original solution

n, m  = list(map(int, input().split()))
g     = {}
used  = {i:[False for _ in range(11)] for i in range(n)}
color     = [0  for _ in range(n)]

for _ in range(m):
    u, v = list(map(int, input().split()))
    u-=1
    v-=1
    if u not in g:
        g[u] = []
    if v not in g:
        g[v] = []
    g[u].append(v)
    g[v].append(u)
    
q = int(eval(input()))
Q = []

for _ in range(q):
    node, dis, col = list(map(int, input().split()))
    Q.append([node-1, dis, col])
Q = Q[::-1]

def bfs(node, dis, col):
    if used[node][dis] == True:
        return
        
    used[node][dis] == True    
    
    if color[node] == 0:
        color[node] = col
        
        
    if node in g and dis > 0:
        for v in g[node]:
            bfs(v, dis-1, col)
            
for node, dis, col in Q:
    bfs(node, dis, col)

for x in color:
    print(x)


# Optimized solution
n, m  = list(map(int, input().split()))
g     = {}
used  = {i:[False for _ in range(11)] for i in range(n)}
color     = [0  for _ in range(n)]

for _ in range(m):
    u, v = list(map(int, input().split()))
    u-=1
    v-=1
    if u not in g:
        g[u] = []
    if v not in g:
        g[v] = []
    g[u].append(v)
    g[v].append(u)
    
q = int(eval(input()))
Q = []

for _ in range(q):
    node, dis, col = list(map(int, input().split()))
    Q.append([node-1, dis, col])
Q = Q[::-1]

def bfs(now, dist, col):
    if dist < 0:
        return
    
    if used[now][dist]:
        return
 
    used[now][dist] = True
    
    if not color[now]:
        color[now] = col
 
    if now in g:
        for x in g[now]:
            bfs(x, dist - 1, col)
            
for node, dis, col in Q:
    bfs(node, dis, col)

for x in color:
    print(x)
# Original solution
from collections import deque

N, M, *L = list(map(int, open(0).read().split()))
AB, VDC = L[:2 * M], L[2 * M + 1:]

E = [[] for _ in range(N + 1)]
for a, b in zip(*[iter(AB)] * 2):
    E[a].append(b)
    E[b].append(a)

colors = [0] * (N + 1)
visited = [-1] * (N + 1)

for v, d, c in reversed(tuple(zip(*[iter(VDC)] * 3))):
    Q = deque([(d, v)])
    while Q:
        cnt, v = Q.popleft()
        if visited[v] >= cnt:
            continue
        if colors[v] == 0:
            colors[v] = c
        visited[v] = cnt
        if cnt > 0:
            Q.extend((cnt - 1, u) for u in E[v])

for c in colors[1:]:
    print(c)


# Optimized solution
from collections import deque

def main():
    N, M, *L = list(map(int, open(0).read().split()))

    E = [[] for _ in range(N + 1)]
    for a, b in zip(*[iter(L[:2 * M])] * 2):
        E[a].append(b)
        E[b].append(a)

    colors = [0] * (N + 1)
    visited = [-1] * (N + 1)

    for v, d, c in reversed(tuple(zip(*[iter(L[2 * M + 1:])] * 3))):
        Q = deque([(d, v)])
        while Q:
            cnt, v = Q.popleft()
            if visited[v] >= cnt:
                continue
            if colors[v] == 0:
                colors[v] = c
            visited[v] = cnt
            if cnt > 0:
                Q.extend((cnt - 1, u) for u in E[v])

    for c in colors[1:]:
        print(c)

if __name__ == '__main__':
    main()
# Original solution
from collections import deque

def main():
    N, M, *L = list(map(int, open(0).read().split()))

    E = [[] for _ in range(N + 1)]
    for a, b in zip(*[iter(L[:2 * M])] * 2):
        E[a].append(b)
        E[b].append(a)

    colors = [0] * (N + 1)
    visited = [False] * (N + 1)

    for v, d, c in reversed(tuple(zip(*[iter(L[2 * M + 1:])] * 3))):
        Q = deque([(d, v)])
        while Q:
            cnt, v = Q.popleft()
            if colors[v] == 0:
                colors[v] = c
            visited[v] = cnt
            if cnt > 0:
                Q.extend((cnt - 1, u) for u in E[v] if visited[u] < cnt)

    for c in colors[1:]:
        print(c)

if __name__ == '__main__':
    main()


# Optimized solution
from collections import deque

def main():
    N, M, *L = list(map(int, open(0).read().split()))

    E = [[] for _ in range(N + 1)]
    for a, b in zip(*[iter(L[:2 * M])] * 2):
        E[a].append(b)
        E[b].append(a)

    colors = [0] * (N + 1)
    visited = [-1] * (N + 1)

    for v, d, c in reversed(tuple(zip(*[iter(L[2 * M + 1:])] * 3))):
        Q = deque([(d, v)])
        while Q:
            cnt, v = Q.popleft()
            if visited[v] >= cnt:
                continue
            if colors[v] == 0:
                colors[v] = c
            visited[v] = cnt
            if cnt > 0:
                Q.extend((cnt - 1, u) for u in E[v] if visited[u] < cnt - 1)

    for c in colors[1:]:
        print(c)

if __name__ == '__main__':
    main()
# Original solution
def painting(N,A,v,d,c):
	if d < 0:
		return
	if A[v][d] == 0:
		A[v][d] = c
		for ni,n in enumerate(N[v]):
			if n == 1:
				painting(N,A,ni,d-1,c)
N,M = list(map(int,input().split()))
nodes = [[0]*N for i in range(N)]
dp = [[0]*11 for i in range(N)]
for m in range(M):
	a,b = list(map(int,input().split()))
	nodes[a-1][b-1] = 1
	nodes[b-1][a-1] = 1
for i in range(N):
	nodes[i][i] = 1
Q = int(eval(input()))
paint = [list(map(int,input().split())) for q in range(Q)]
paint.reverse()
for q in paint:
	v,d,c = q
	v = v - 1
	painting(nodes,dp,v,d,c)
print(("\n".join(list(map(str,[dp[i][0] for i in range(N)])))))

# Optimized solution
def painting(N,A,v,d,c):
	if d < 0:
		return
	if A[v][d] == 0:
		A[v][d] = c
		i = 0
		while i < len(N):
			if 1 in N[v][i:]:
				i = i + N[v][i:].index(1)
			else:
				break
			painting(N,A,i,d-1,c)
			i = i + 1
			
N,M = list(map(int,input().split()))
nodes = [[0]*N for i in range(N)]
dp = [[0]*11 for i in range(N)]
for m in range(M):
	a,b = list(map(int,input().split()))
	nodes[a-1][b-1] = 1
	nodes[b-1][a-1] = 1
for i in range(N):
	nodes[i][i] = 1
Q = int(eval(input()))
paint = [list(map(int,input().split())) for q in range(Q)]
paint.reverse()
for q in paint:
	v,d,c = q
	v = v - 1
	painting(nodes,dp,v,d,c)
print(("\n".join(list(map(str,[dp[i][0] for i in range(N)])))))