g1 = [[1, 2], [], [0]] g2 = {0: [1, 2], 1: [], 2: [0]} g3 = [{1, 2}, {}, {0}] g4 = {0: {1, 2}, 1: {}, 2: {0}}
V, E = [int(x) for x in sys.stdin.readline().split()]
graph = [[] for _ in range(V)]
for _ in range(E):
u, v = [int(x) for x in sys.stdin.readline().split()]
graph[u - 1].append(v - 1)
graph[v - 1].append(u - 1) # 무향 그래프에서만 필요. 유향 그래프라면 이 줄이 없어야 한다.
V, E = [int(x) for x in sys.stdin.readline().split()]
wgraph = [{} for _ in range(V)]
for _ in range(E):
u, v, w = [int(x) for x in sys.stdin.readline().split()]
try:
wgraph[u - 1][v - 1] = min(wgraph[u - 1][v - 1], w)
except KeyError:
wgraph[u - 1][v - 1] = w
V, E = [int(x) for x in sys.stdin.readline().split()]
wgraph = [{} for _ in range(V)]
for _ in range(E):
u, v, w = [int(x) for x in sys.stdin.readline().split()]
if (e := wgraph[u - 1]).get(v - 1, INF) > w:
e[v - 1] = w