#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll m = 1e9 + 7;
ll mpow(ll a, ll n) {
  ll ret = 1;
  while (n) {
    if (n % 2) {
      ret *= a;
      ret %= m;
    }
    a = (a * a) % m;
    n /= 2;
  }
  return ret;
}
int main () {
  int N, M, K;
  cin >> N >> M >> K;
  if (N - M > K) {
    cout << 0 << endl;
    return 0;
  }
  ll kai[2000004];
  ll fkai[2000002];
  kai[0] = 1;
  for (int i = 1; i <= N + M; i ++) {
    kai[i] = kai[i - 1] * (ll)i;
    kai[i] %= m;
  }
  fkai[N + M] = mpow(kai[N + M], m - 2);
  for (int i = N + M; i > 0; i --) {
    fkai[i - 1] = fkai[i] * (ll)i;
    fkai[i - 1] %= m;
  }
  ll ans = (kai[N + M] * fkai[M]) % m;
  ans *= fkai[N];
  ans %= m;
  if (K >= N) {
    cout << ans << endl;
    return 0;
  }
  ll kj = kai[N + M] * fkai[M + K + 1];
  kj %= m;
  kj *= fkai[N -K - 1];
  kj %= m;
  ans -= kj;
  if (ans < 0) ans += m;
  cout << ans << endl;
}
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
//---------------------------------------------------------------------------------------------------
template<int MOD> struct ModInt {
    static const int Mod = MOD; unsigned x; ModInt() : x(0) { }
    ModInt(signed sig) { x = sig < 0 ? sig % MOD + MOD : sig % MOD; }
    ModInt(signed long long sig) { x = sig < 0 ? sig % MOD + MOD : sig % MOD; }
    int get() const { return (int)x; }
    ModInt &operator+=(ModInt that) { if ((x += that.x) >= MOD) x -= MOD; return *this; }
    ModInt &operator-=(ModInt that) { if ((x += MOD - that.x) >= MOD) x -= MOD; return *this; }
    ModInt &operator*=(ModInt that) { x = (unsigned long long)x * that.x % MOD; return *this; }
    ModInt &operator/=(ModInt that) { return *this *= that.inverse(); }
    ModInt operator+(ModInt that) const { return ModInt(*this) += that; }
    ModInt operator-(ModInt that) const { return ModInt(*this) -= that; }
    ModInt operator*(ModInt that) const { return ModInt(*this) *= that; }
    ModInt operator/(ModInt that) const { return ModInt(*this) /= that; }
    ModInt inverse() const { long long a = x, b = MOD, u = 1, v = 0;
        while (b) { long long t = a / b; a -= t * b; std::swap(a, b); u -= t * v; std::swap(u, v); }
        return ModInt(u); }
    bool operator==(ModInt that) const { return x == that.x; }
    bool operator!=(ModInt that) const { return x != that.x; }
    ModInt operator-() const { ModInt t; t.x = x == 0 ? 0 : Mod - x; return t; }
};
template<int MOD> ostream& operator<<(ostream& st, const ModInt<MOD> a) { st << a.get(); return st; };
template<int MOD> ModInt<MOD> operator^(ModInt<MOD> a, unsigned long long k) {
    ModInt<MOD> r = 1; while (k) { if (k & 1) r *= a; a *= a; k >>= 1; } return r; }
typedef ModInt<1000000007> mint;
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧  
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     
　　　　／　　　＼　 　  |　|     
　　　 /　　 /￣￣￣￣/　　|  
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿  
　 　　　＼/＿＿＿＿/　（u　⊃  
---------------------------------------------------------------------------------------------------*/





typedef long long ll;
int N;
vector<pair<int, ll>> E[301010];
//---------------------------------------------------------------------------------------------------
ll xo[301010];
void dfs(int cu, int pa = -1) {
    fore(p, E[cu]) if (p.first != pa) {
        xo[p.first] = xo[cu] ^ p.second;
        dfs(p.first, cu);
    }
}
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> N;
    rep(i, 0, N - 1) {
        int a, b; ll c; cin >> a >> b >> c;
        a--; b--;
        E[a].push_back({ b, c });
        E[b].push_back({ a, c });
    }

    dfs(0);

    mint ans = 0;
    rep(d, 0, 71) {
        mint a = 1;
        ll mask = 1;
        rep(i, 0, d) a *= 2, mask *= 2;

        mint cnt0 = 0, cnt1 = 0;
        rep(i, 0, N) {
            if (xo[i] & mask) cnt1 += 1;
            else cnt0 += 1;
        }

        mint cnt = 0;
        rep(i, 0, N) {
            if (xo[i] & mask) cnt += cnt0;
            else cnt += cnt1;
        }
        cnt /= 2;
        ans += a * cnt;
    }
    cout << ans << endl;
}