#include #if __has_include() #include using namespace atcoder; #endif #define rep(i, n) for (int i = 0; i < (n); ++i) using std::cin; using std::cout; using std::vector; using std::array; using mint = modint1000000007; int main() { int n; cin >> n; vector> es(n-1); for (auto& [a, b, c] : es) { cin >> a >> b >> c; --a; --b; } mint ans; rep(i, 30) { dsu t(n); for (auto& [a, b, c] : es) { if (c>>i&1) { t.merge(a, b); } } for (auto g : t.groups()) { mint x = g.size(); x = x * (x-1) / 2; ans += x * (1<