#include using namespace std; using ll = long long; #define all(a) (a).begin(), (a).end() #define pb push_back #define fi first #define se second mt19937_64 rng(chrono::system_clock::now().time_since_epoch().count()); const ll MOD1000000007 = 1000000007; const ll MOD998244353 = 998244353; const ll MOD[3] = {999727999, 1070777777, 1000000007}; const ll LINF = 1LL << 60LL; const int IINF = (1 << 30) - 2; struct union_find{ vector par; vector siz; union_find(int n) : par(n), siz(n, 1){ for(int i=0; i> n >> m; vector>> es(1e5+2); vector> T(1e5+1); for(int i=0; i> u >> v >> w; es[w].pb({u, v}); } int q; cin >> q; for(int i=0; i> r; T[r].pb(i); } vector ans(q); union_find uf(n); int con = n; for(int i=0; i<=1e5; i++){ for(auto [u, v] : es[i]){ if(!uf.same(u, v)){ con--; uf.unite(u, v); } } for(int j : T[i]) ans[j] = con; } for(int i=0; i> T; while(T--) solve(); }