#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define int long long
#define all(x) (x).begin(), (x).end()
typedef long double ld;
typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<vector<int>> vvi;
typedef vector<vector<bool>> vvb;
typedef vector<vector<ll>> vvll;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef map<int, int> mii;
typedef unordered_map<int, int> umii;
const int mod = 1e9 + 7;
const int inf = INTMAX_MAX;
const bool tc = false;
#include <bits/stdc++.h>
using namespace std;
class DisjointSets {
private:
vector<int> parents;
vector<int> sizes;
public:
DisjointSets(int size) : parents(size), sizes(size, 1) {
for (int i = 0; i < size; i++) { parents[i] = i; }
}
/** @return the "representative" node in x's component */
int find(int x) { return parents[x] == x ? x : (parents[x] = find(parents[x])); }
/** @return whether the merge changed connectivity */
bool unite(int x, int y) {
int x_root = find(x);
int y_root = find(y);
if (x_root == y_root) { return false; }
if (sizes[x_root] < sizes[y_root]) { swap(x_root, y_root); }
sizes[x_root] += sizes[y_root];
parents[y_root] = x_root;
return true;
}
/** @return whether x and y are in the same connected component */
bool connected(int x, int y) { return find(x) == find(y); }
};
struct edge {
int u, v, w;
bool operator<(const edge &other) const {
if (w != other.w) return w < other.w;
else if (u != other.u) return u < other.u;
else return v < other.v;
}
};
struct slope {
int a, b;
void add(slope &other) {
a += other.a;
b += other.b;
}
void remove(slope &other) {
a -= other.a;
b -= other.b;
}
int eval(int &x) { return a*x + b; }
};
struct ev {
int t, tim; slope s;
bool operator<(const ev &other) const {
if (tim != other.tim) return tim < other.tim;
else return t < other.t;
}
};
inline void solve() {
int n, m;
cin >> n >> m;
vector<edge> es(m); for (int i = 0; i < m; i++) {
cin >> es[i].u >> es[i].v >> es[i].w;
es[i].u--; es[i].v--;
}
sort(all(es));
multiset<ev> events;
for (int i = 0; i < m; i++) {
int rb = 1e18;
DisjointSets dsu(n);
for (int j = i + 1; j < m; j++) {
dsu.unite(es[j].u, es[j].v);
if (dsu.connected(es[i].u, es[i].v)) {
rb = es[j].w;
break;
}
}
int lb = -1e18;
dsu = DisjointSets(n);
for (int j = i - 1; j >= 0; j--) {
dsu.unite(es[j].u, es[j].v);
if (dsu.connected(es[i].u, es[i].v)) {
lb = es[j].w;
break;
}
}
int l = (lb + es[i].w + 1)/2, r = (es[i].w + rb - 1)/2;
if (l > r) continue;
slope right = {1, -es[i].w}; // type time slope
ev Radd = {1, es[i].w, right};
ev Rrem = {0, r + 1, right};
events.insert(Radd); events.insert(Rrem);
slope left = {-1, es[i].w}; // type time slope
ev Ladd = {1, l, left};
ev Lrem = {0, es[i].w + 1, left};
events.insert(Ladd); events.insert(Lrem);
}
int q; cin >> q; slope cur{0, 0};
while (q--) {
int x; cin >> x;
while (!events.empty()) {
if ((*events.begin()).tim > x) break;
auto top = *events.begin();
if (top.t) cur.add(top.s);
else cur.remove(top.s);
events.erase(events.begin());
}
cout << cur.eval(x) << '\n';
}
}
void setIO(string s) {
freopen((s + ".in").c_str(), "r", stdin);
freopen((s + ".out").c_str(), "w", stdout);
}
signed main() {
ios::sync_with_stdio(false);
cout.tie(0);
cin.tie(0);
//setIO();
int t = 1;
if (tc) {
cin >> t;
}
while (t--) {
solve();
}
}