#include const int Mod = 1000000007; typedef struct Edge { struct Edge *next; int v, cost; } edge; int main() { int i, N, u, w, c; edge *adj[100001] = {}, e[200001], *p; scanf("%d", &N); for (i = 0; i < N - 1; i++) { scanf("%d %d %d", &u, &w, &c); e[i*2].v = w; e[i*2+1].v = u; e[i*2].cost = c; e[i*2+1].cost = c; e[i*2].next = adj[u]; e[i*2+1].next = adj[w]; adj[u] = &(e[i*2]); adj[w] = &(e[i*2+1]); } int par[100001] = {}, q[100001], head, tail; par[1] = 1; q[0] = 1; for (head = 0, tail = 1; head < tail; head++) { u = q[head]; for (p = adj[u]; p != NULL; p = p->next) { w = p->v; if (par[w] == 0) { par[w] = u; q[tail++] = w; } } } int k, dp[100001], bit; long long ans = 0, tmp; for (k = 0, bit = 1; k < 30; k++, bit <<= 1) { for (head = tail - 1; head >= 0; head--) { u = q[head]; dp[u] = 1; for (p = adj[u]; p != NULL; p = p->next) { w = p->v; if (w == par[u] || (p->cost & bit) == 0) continue; ans += (long long)bit * dp[u] % Mod * dp[w] % Mod; dp[u] += dp[w]; } } } printf("%lld\n", ans % Mod); fflush(stdout); return 0; }