#include <bits/stdc++.h>
using namespace std;
#define ios ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl '\n'
#define debugg(x) cout<<#x<<'='<<x<<endl;
#define debug1(x,y,z) cout<<#x<<' '<<x<<' '<<#y<<' '<<y<<' '<<#z<<' '<<z<<endl;
#define debug cout<<endl<<"********"<<endl;
#define ll long long
#define ull unsigned long long
#define ding cerr<<endl<<"Time: "<<(clock() * 1000. / CLOCKS_PER_SEC)<<" ms"<<endl;
#define ld long double 
#define itn int
#define pi (int)(3.1415926536)
#define pii pair<int,int>
#define rep(I, A, B) for (int I = (A); I <= (B); ++I)
#define dwn(I, A, B) for (int I = (A); I >= (B); --I)
#define repp(i,a,b) for(int i=(a);i<(b);i++)
#define mod (ll)(1e9+7)
#define mod1 (ll)(1e9)
#define int ll
void fre(){
    freopen("test.in","r",stdin);
    freopen("test.out","w",stdout);
}
void fc(){fclose(stdin);fclose(stdout);}
inline ll ccin(){
    ll x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){
        if(ch=='-') f=-1;
        ch=getchar();
    }
    while(ch>='0' && ch<='9') x=x*10+ch-'0',ch=getchar();
    return x*f;
}
inline void cou(ll x){
    if(x<0) putchar('-'),x=-x;
    if(x>9) cou(x/10);
    putchar(x%10+'0');
}



const int maxn=2e5+10;
const ll inf=1e16;
const int maxm=5e5+10;

int n;
struct node{
    int v;int w;
};
vector<node> yuan[maxn];
int zhi[maxn],cnt0[70],cnt1[70];
void dfs(int now,int fa,int val){
    zhi[now]=val;
    for(int i=0;i<yuan[now].size();i++){
        int v=yuan[now][i].v;
        if(v==fa) continue;
        dfs(v,now,val^yuan[now][i].w);
    }
}

signed main(){
    ios;
    cin>>n;
    for(int i=1;i<n;i++){
        int a1,a2,a3;cin>>a1>>a2>>a3;
        yuan[a1].push_back((node){a2,a3});
        yuan[a2].push_back((node){a1,a3});
    }
    dfs(1,0,0);
    for(int i=0;i<=61;i++){
        int now=(1LL<<i);
        for(int j=1;j<=n;j++){
            if(now&zhi[j]) cnt1[i]++;
            else cnt0[i]++;
        }
    }
    ll ans=0;
    for(int i=0;i<=61;i++){
        ll now=(1LL<<i)%mod;
        ll cnt=cnt1[i]*cnt0[i]%mod;
        ans=(ans+now*cnt)%mod;
    }
    cout<<ans<<endl;
    ding;return 0;
}
#include <bits/stdc++.h>
#define Rep(i,n,m) for(int i=(int)(n);i<(int)(m);i++)
#define rep(i,n) Rep(i,0,n)
#define all(v) v.begin(),v.end()
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
#define _GLIBCXX_DEBUG
vll g;
using pii=pair<int,ll>;
using graph=vector<vector<pii>>;
const ll mod=1000000007;

void dfs(graph &G,int v,int p,ll m){
  g[v]=m;
  for(auto q:G[v]){
    if(q.first==p) continue;
    dfs(G,q.first,v,m^q.second);
  }
}
int main(){
  int N;cin>>N;
  vll pw(60);pw[0]=1;
  rep(i,59) pw[i+1]=pw[i]*2;
  graph G(N);
  rep(i,N-1){
    int x,y;ll z;cin>>x>>y>>z;x--;y--;
    G[x].push_back({y,z});G[y].push_back({x,z});
  }
  g=vll(N);
  dfs(G,0,-1,0);
  vll cn(60);
  rep(i,N){
    rep(j,60){
      if(g[i]&pw[j]) cn[j]++;
    }
  }
  ll ans=0;
  

  rep(i,60){
    ans+=pw[i]%mod*cn[i]%mod*(N-cn[i])%mod;
    ans%=mod;
  }
  cout << ans << endl;
  return 0;
}