import sys input = sys.stdin.readline N,M=map(int,input().split()) # UnionFind Group = [i for i in range(N+1)] # グループ分け Nodes = [1]*(N+1) # 各グループのノードの数 def find(x): while Group[x] != x: x=Group[x] return x def Union(x,y): if find(x) != find(y): if Nodes[find(x)] < Nodes[find(y)]: Nodes[find(y)] += Nodes[find(x)] Nodes[find(x)] = 0 Group[find(x)] = find(y) else: Nodes[find(x)] += Nodes[find(y)] Nodes[find(y)] = 0 Group[find(y)] = find(x) X=[] for i in range(M): x,y,w=map(int,input().split()) X.append([w,x,y]) T=int(input()) R=list(map(int,input().split())) for i in range(T): X.append([R[i],10**9,i]) X.sort() NOW=N ANS=[0]*T for w,x,y in X: if x==10**9: ANS[y]=NOW else: if find(x)!=find(y): Union(x,y) NOW-=1 for ans in ANS: print(ans)