// see https://github.com/LumaKernel/vimfiles/tree/master/snippets/cp-cpp/temp.snip
/// --- .lumrc Template {{{ ///
// #define DEBUG
// #undef DEBUG
// #define assert(...)
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;
using P = tuple<ll, ll>;
using P3 = tuple<ll, ll, ll>;
using VI = vector<int>;
using VL = vector<ll>;
using VVI = vector<VI>;
using VVL = vector<VL>;
using VP = vector<P>;
using VS = vector<string>;

#define omajinai ios::sync_with_stdio(false),cin.tie(0)

#define FOR(i,a,b) for(int i=int(a);i<int(b);++i)
#define FORI(i,a,b) for(int i=int(a);i<=int(b);++i)
#define REP(i,n) FOR(i,0,n)
#define REPI(i,n) FORI(i,0,n)
#define RFOR(i,a,b) for(int i=int(b)-1;i>=int(a);--i)
#define RFORI(i,a,b) for(int i=int(b);i>=int(a);--i)
#define RREP(i,n) RFOR(i,0,n)
#define RREPI(i,n) RFORI(i,0,n)

#define ALL(a) begin(a),end(a)
#define UNIQUE(a) (a).erase(unique(ALL(a)),(a).end())
#define PB push_back
#define EACH(i,c) REP(i,(c).size())
#define REACH(i,c) RREP(i,(c).size())
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(ALL(c))

#define BR cout<<"\n";

#ifdef DEBUG
#define dump(...) cerr<<"["<<__LINE__<< "] "<<#__VA_ARGS__<<" = "<<make_tuple(__VA_ARGS__)<<"\n";
#else
#define dump(...)
#endif

#define YES(x) cout<<((x)?"YES":"NO")<<"\n";
#define Yes(x) cout<<((x)?"Yes":"No")<<"\n";
#define yes(x) cout<<((x)?"yes":"no")<<"\n";

int __int_temp; ll __ll_temp; string __string_temp;
#define oini (omajinai, cin>>__int_temp, __int_temp)
#define oinl (omajinai, cin>>__ll_temp, __ll_temp)
#define oins (omajinai, cin>>__string_temp, __string_temp)
#define ini (cin>>__int_temp, __int_temp)
#define inl (cin>>__ll_temp, __ll_temp)
#define ins (cin>>__string_temp, __string_temp)

#define isInside(y,x) (0<=(y)&&(y)<h&&0<=(x)&&(x)<w)

#define fi(x) (get<0>(x))
#define se(x) (get<1>(x))
#define th(x) (get<2>(x))
#define fo(x) (get<3>(x))
#define fif(x) (get<4>(x))

template <typename T> ostream &operator<<(ostream &o, const vector<T> &v) { o << '{'; EACH(i, v) o << v[i] << (i != (int)v.size()-1 ? ", " : ""); o << "}";  return o; }

template<int n, class...T> typename enable_if<(n>=sizeof...(T))>::type _ot(ostream &, tuple<T...> const &){}
template<int n, class...T> typename enable_if<(n< sizeof...(T))>::type _ot(ostream & os, tuple<T...> const & t){ os << (n==0?"":", ") << get<n>(t); _ot<n+1>(os, t); }
template<class...T> ostream & operator<<(ostream & os, tuple<T...> const & t){ _ot<0>(os, t); return os; }

template <typename T> inline void smax(T &a, T b) { a = a > b ? a : b; }
template <typename T> inline void smin(T &a, T b) { a = a < b ? a : b; }

template<typename T> inline int intlog2(T x);
template<> inline int intlog2(int x) { return x == 0 ? 0 : 32 - __builtin_clz(x); }
template<> inline int intlog2(ll x) { return x == 0 ? 0 : 64 - __builtin_clzll(x); }

vector<string> split(const string& s, char delim) {
  std::vector<string> elms;
  size_t offset = 0;
  while (true) {
    size_t next = s.find_first_of(delim, offset);
    if (next == string::npos) {
      elms.push_back(s.substr(offset));
      return elms;
    }
    elms.push_back(s.substr(offset, next - offset));
    offset = next + 1;
  }
}

constexpr double PI = acos(-1);

/// }}}--- ///

constexpr int INF = 1e9+1;
constexpr ll LINF = 1e18+1;
constexpr int MOD = 1e9+7;


/// --- modulo Library {{{ ///
constexpr ll extgcd(ll a, ll b, ll& x, ll& y) {
  if(b==0) {
    x = 1; y = 0;
    return a;
  }
  ll d = extgcd(b, a % b, y, x);
  y -= (a / b) * x;
  return d;
}
constexpr ll modpow(ll a, ll b, ll mod = 1e9 + 7) {
  a = (a % mod + mod) % mod;
  ll r = 1;
  while(b){
    if(b & 1) r = r * a % mod;
    a = a * a % mod;
    b >>= 1;
  }
  return r;
}
constexpr ll modinv(ll a, ll mod = 1e9 + 7) {
  a = (a % mod + mod) % mod;
  ll x = 0, y = 0;
  extgcd(a, mod, x, y);
  return (x % mod + mod) % mod;
}
template<int N, int mod = 1e9 + 7> struct Factorial {
  int arr[N+1], inv[N+1];
  int operator[](int i) const { return arr[i]; }
  constexpr Factorial(): arr(), inv() {
    arr[0] = 1;
    for(int i = 1; i <= N; i++) {
      arr[i] = (ll) i * arr[i - 1] % mod;
    }
    inv[N] = modinv(arr[N], mod);
    for(int i = N-1; i >= 0; i--) {
      inv[i] = (ll) (i + 1) * inv[i + 1] % mod;
    }
  }
  int C(int n, int r) {
    if(n < 0 || r < 0 || n < r) return 0;
    return modmul(arr[n], modmul(inv[r], inv[n - r], mod), mod);
  }
};
/// }}}--- ///

// constexpr int N = 1e5 + 10;
// constexpr Factorial<N> fact;

/// --- Union Find Library {{{ ///

struct UF {
  int n;
  VI par, rank;
  UF(int n): n(n), par(n, -1), rank(n, 0) {}
  int find(int x) {
    return par[x] < 0 ? x : par[x] = find(par[x]);
  }
  int size(int x) {
    return -par[find(x)];
  }
  bool same(int a, int b) {
    return find(a) == find(b);
  }
  void unite(int a, int b) {
    a = find(a);
    b = find(b);
    if(a == b) return;
    if(rank[a] > rank[b]) swap(a, b);
    par[b] += par[a];
    par[a] = b;
    if(rank[a] == rank[b]) rank[b]++;
  }
};

/// }}}--- ///

using E = tuple<int, int, int>;
using D = tuple<int, int>;
vector<E> g;

const int N = 1e3 + 100;
vector<int> tree[N];
int dep[N];
int par[N];
int w[N][N];

void dfs(int i, int p = -1, int d = 0) {
  dep[i] = d;
  par[i] = p;
  for(int j : tree[i]) if(j != p) {
    dfs(j, i, d + 1);
  }
}

int solve(int i, int j) {
  if(dep[i] > dep[j]) swap(i, j);
  int res = 0;
  dump(i, j);
  dump(dep[i], dep[j]);
  while(dep[i] != dep[j]) {
    res = max(res, w[j][par[j]]);
    j = par[j];
  }
  while(i != j) {
    res = max(res, w[j][par[j]]);
    res = max(res, w[i][par[i]]);
    j = par[j];
    i = par[i];
  }
  return res;
}

int used[N][N];

int main() {
  int n = ini, m = ini;
  ll x = inl;

  REP(i, m) {
    int a = ini, b = ini, c = ini;
    a--; b--;
    g.emplace_back(c, a, b);
    w[a][b] = c;
    w[b][a] = c;
  }
  SORT(g);
  UF treeone(n);
  // kruskal
  ll cost = 0;
  for(auto el : g) {
    int a = se(el), b = th(el);
    ll c = fi(el);
    if(!treeone.same(a, b)) {
      treeone.unite(a, b);
      cost += c;
      tree[a].emplace_back(b);
      tree[b].emplace_back(a);
      used[a][b] = 1;
    }
  }
  if(cost > x) {
    cout << 0 << endl;
    return 0;
  }
  dump(1);
  dfs(0);
  dump(2);
  ll rest = x - cost;

  int white = 0;
  int any = 0;
  for(auto el : g) {
    int a = se(el), b = th(el);
    ll c = fi(el);
    if(used[a][b]) {
      if(rest == 0) any++;
      else white++;
      continue;
    }
    int r = solve(a, b);
    int nr = rest - c + r;

    if(nr == 0) {
      any++;
    } else if (nr > 0) {

      white++;
    } else {
    }
  }
  dump(4);

  int ot = m - white - any;

  if(rest == 0) {
    ll ans = modpow(2, any) - 2;
    ans *= modpow(2, ot);
    ans = (ans % MOD + MOD) % MOD;
    cout << ans << endl;
    return 0;
  }

  dump(ot, m, white, any);
  ll ans = modpow(2, any) - 1;
  ans *= modpow(2, ot);
  ans %= MOD;
  ans *= 2;
  ans = (ans % MOD + MOD) % MOD;
  cout << ans << endl;
}


Measured memory_bytes: 8704