#include <bits/stdc++.h>
using i64 = long long;
#ifdef DEBUG
#include "debug.h"
#else
#define debug(...) void(23)
#endif
struct DSU {
std::vector<int> f, siz;
DSU() {}
DSU(int n) {
init(n);
}
void init(int n) {
f.assign(n, 0);
siz.assign(n, 1);
std::iota(f.begin(), f.end(), 0);
}
int get(int x) {
while (x != f[x]) {
x = f[x] = f[f[x]];
}
return x;
}
bool unite(int a, int b) {
a = get(a), b = get(b);
if (a == b) {
return false;
} else if (siz[a] > siz[b]) {
std::swap(a, b);
}
f[a] = b;
siz[b] += siz[a];
return true;
}
bool same(int a, int b) {
return get(a) == get(b);
}
int size(int x) {
return siz[get(x)];
}
};
int main() {
std::ios_base::sync_with_stdio(false);
std::cin.tie(nullptr);
int N, M;
std::cin >> N >> M;
std::vector<std::array<int, 3>> A(M);
for (int i = 0; i < M; ++i) {
std::cin >> A[i][1] >> A[i][2] >> A[i][0];
--A[i][1], --A[i][2];
}
std::sort(A.begin(), A.end());
int Q;
std::cin >> Q;
std::vector<int> X(Q);
for (int i = 0; i < Q; ++i) {
std::cin >> X[i];
}
DSU dsu;
std::vector<std::array<int, 4>> vec;
for (int i = 0; i < M; ++i) {
dsu.init(N);
int c = A[i][0];
int j = i + 1;
while (j < M) {
dsu.unite(A[j][1], A[j][2]);
if (dsu.same(A[i][1], A[i][2])) {
break;
}
j++;
}
int xr;
if (j == M) {
xr = int(1E9) + 5;
} else {
int cr = A[j][0];
xr = (c + cr + 1) >> 1;
}
dsu.init(N);
j = i - 1;
while (j >= 0) {
dsu.unite(A[j][1], A[j][2]);
if (dsu.same(A[i][1], A[i][2])) {
break;
}
j--;
}
int xl;
if (j == -1) {
xl = -1;
} else {
int cl = A[j][0];
xl = (c + cl + 1) >> 1;
}
debug(xl, xr, c);
vec.push_back({xl, +c, 0, +1});
vec.push_back({c, -c, 0, -1});
vec.push_back({c, -c, 1, +1});
vec.push_back({xr, +c, 1, -1});
}
std::sort(vec.begin(), vec.end());
int ptr = 0;
i64 cur = 0;
std::array<i64, 2> cnt {};
for (int i = 0; i < Q; ++i) {
while (ptr < vec.size() && vec[ptr][0] <= X[i]) {
cur += vec[ptr][1];
cnt[vec[ptr][2]] += vec[ptr][3];
ptr++;
}
i64 ans = cur - cnt[0] * X[i] + cnt[1] * X[i];
// for (auto[l, r, w] : vec) {
// if (l <= X[i] && X[i] < r) {
// ans += std::abs(w - X[i]);
// debug(w);
// }
// }
std::cout << ans << '\n';
debug();
}
return 0;
}