#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
#define fr(i, a, b) for (ll i = a; i < b; i++)
#define rf(i, a, b) for (ll i = a; i >= b; i--)
typedef std::vector<long long> vi;
#define F first
#define S second
#define fast                      \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);                   \
    cout.tie(0);
#define mod 1000000007
#define PB push_back
#define MP make_pair
#define PI 3.14159265358979323846
#define all(a) a.begin(), a.end()
#define mx(a) *max_element(all(a))
#define mn(a) *min_element(all(a))
const ll INF = LLONG_MAX / 2;
const ll N = 2e5 + 1;
using namespace std;
ll n, m, mark[200005], dist[200005];
vector<pair<ll, ll>> adj[200005];
ll p = 0;
void dfs(ll s, ll val)
{
    mark[s] = 1;
    dist[s] = val;
    for (auto i : adj[s])
    {
        ll x = i.F, w = i.S;
        // cout << x << " " << w << "\n";
        if (mark[x] == 1)
        {
            continue;
        }
        dfs(x, val ^ w);
    }
}
void solve()
{
    std::cin >> n;
    m = n - 1;
    fr(i, 0, m)
    {
        ll l, r, d;
        cin >> l >> r >> d;
        adj[l].PB({r, d});
        adj[r].PB({l, d});
    }
    dist[1] = 0;
    dfs(1, 0);
    ll ans = 0;
    for (ll i = 0; i < 62; i++)
    {
        ll d = 1;
        ll c = d << i, co = 0;
        fr(j, 1, n + 1)
        {
            if (dist[j] >> i & 1)
                co++;
        }
        c = c % mod;
        ans = (ans + (((n - co) * co) % mod) * c) % mod;
    }
    cout << ans << "\n";
    return;
}
int main()
{
    fast;
    ll _ = 1, counti = 0;
    // std::cin >> _;
    while (_--)
    {
        // counti++;
        // cout << "Case #" << counti << ": ";
        solve();
    }
}
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod=1e9+7;
const int maxn=2e6+5;
int n,m,k;
int inv[maxn];
int main()
{
    
    scanf("%d%d%d",&n,&m,&k);
    if(n>m+k)
    {
        printf("0");
        return 0;
    }
    int ans=1,res=1;
    inv[0]=inv[1]=1;
    for(int i=2;i<=max(n,m+k+1);i++)
        inv[i]=1LL*inv[mod%i]*(mod-mod/i)%mod;
    for(int i=1;i<=m+n;i++) ans=1LL*ans*i%mod;
    res=ans;
    for(int i=1;i<=n;i++) ans=1LL*ans*inv[i]%mod;
    for(int i=1;i<=m;i++) ans=1LL*ans*inv[i]%mod;
    for(int i=1;i<=n-k-1;i++) res=1LL*res*inv[i]%mod;
    for(int i=1;i<=m+k+1;i++) res=1LL*res*inv[i]%mod;
    if(n-k-1<0) res=0;
    printf("%d",((ans-res)%mod+mod)%mod);
    return 0;
}