import sys input = sys.stdin.readline class UnionFind(): def __init__(self, n=1): self.par = [i for i in range(n)] self.rank = [0 for _ in range(n)] self.size = [1 for _ in range(n)] def find(self, x): if self.par[x] == x: return x else: self.par[x] = self.find(self.par[x]) return self.par[x] def union(self, x, y): x = self.find(x) y = self.find(y) if x != y: if self.rank[x] < self.rank[y]: x, y = y, x if self.rank[x] == self.rank[y]: self.rank[x] += 1 self.par[y] = x self.size[x] += self.size[y] def is_same(self, x, y): return self.find(x) == self.find(y) def get_size(self, x): x = self.find(x) return self.size[x] N, M = map(int, input().split()) Edge = [] for i in range(M): a, b, w = map(int, input().split()) Edge.append((w, a, b)) T = int(input()) R = list(map(int, input().split())) RR = [] for i in range(T): RR.append((R[i], i)) RR.sort() Edge.sort(reverse=True) ans = [-1] * T U = UnionFind(N) now = N for i in range(T): while Edge and Edge[-1][0] <= RR[i][0]: _, a, b = Edge.pop() if U.is_same(a, b): continue U.union(a, b) now -= 1 ans[RR[i][1]] = now for a in ans: print(a)