#include "bits/stdc++.h"
using namespace std;
void __dump(int x){cerr << x;}
void __dump(long long x){cerr << x;}
void __dump(long double x){cerr << fixed << setprecision(3) << x;}
void __dump(char x){cerr << '\'' << x << '\'';}
void __dump(const string &x){cerr << '"' << x << '"';}
void __dump(const char *x){cerr << '"' << x << '"';}
void __dump(bool x){cerr << (x ? "true" : "false");}
void _dump(){cerr << "\n";}
template <typename T, typename U> void __dump(const pair<T, U> &x){cerr << '{'; __dump(x.first); cerr << ','; __dump(x.second); cerr << '}';}
template <typename T, typename U, typename V> void __dump(const tuple<T, U, V> &x){cerr << '{'; __dump(get<0>(x)); cerr << ',';  __dump(get<1>(x)); cerr << ',';  __dump(get<2>(x)); cerr << '}';}
template <typename T> void __dump(const T& x){int f=0; cerr << '{'; for(auto&i:x) cerr << (f++ ? "," : ""), __dump(i); cerr << "}";}
template <typename T, typename ... U> void _dump(T t, U ... u){__dump(t); if(sizeof...(u)) cerr << ", "; _dump(u...);}
#ifdef ilyes
	#define dump(x ...) cerr  <<  "|dumping| "  <<  # x  <<  "  =  ", _dump(x) 
#else
	#define dump(...) -35.53
#endif
// #define int long long
#define FAST ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define size(x) (int)x.size()
#define all(x) x.begin(),x.end()
#define ln '\n'
#define __ ' '
#define LL long long
#define pii pair<int,int>
struct Dsu {
    vector<int> _leader, _size;
    Dsu(int _n) {
        _leader.assign(_n+1, 0); _size.assign(_n+1, 0);
		 for(int i=1; i<=_n; ++i) _leader[i]=i, _size[i]=1;
    }
    int leader(int x) {return (_leader[x]==x) ? x : _leader[x]=leader(_leader[x]);}
    void unite(int x, int y) {
		x = leader(x); y = leader(y);
		if (x == y) return;

		_leader[y] = x;
		_size[x] += _size[y];
    }
};
namespace Mm{
	const int _MOD = 1e9 + 7;
	inline int mul(const LL &x, const LL &y) { return (x*y)%_MOD; }
	#define _mul(a,b) a=mul(a,b)
	inline int add(const LL &x, const LL &y) { LL z=x+y; return (z>=_MOD+_MOD)?z%_MOD:((z>=_MOD)?z-_MOD:((z<0)?z+_MOD:z)); }
	#define _add(a,b) a=add(a,b)
	inline int power(const LL &x, const LL &n){if(n==0)return 1;int y=power(x, n>>1);y=mul(y,y);return (n&1)?mul(y,x):y;}
} using namespace Mm;
const int INF = 1e9;
const int N = 1e3;
int n,m;
LL x;
vector<tuple<int,int,int>> edg, extra;
vector<pii> adj[N+3];
Dsu dsu(N);
LL sumW;
int ans;
int equ, upper;
int maxW[N+3][N+3];
int seen[N+3];

void explore(int src, int u, int mx){
	maxW[src][u] = mx;
	seen[u] = true;
	for(auto el: adj[u]){
		int v,w; tie(v,w) = el;
		// dump(u,v,w);
		if(!seen[v]) explore(src, v, max(mx, w));
	}
}

int main(){ FAST
	cin >> n >> m >> x;
	for(int i=1; i<=m; ++i){
		int u, v, w; cin >> u >> v >> w;
		edg.emplace_back(u, v, w);
	}
	sort(all(edg), [&](tuple<int,int,int>&f, tuple<int,int,int>&s){ return get<2>(f) < get<2>(s); });

	for(auto el: edg){
		int u,v,w; tie(u,v,w) = el;
		if(dsu.leader(u) == dsu.leader(v)){
			extra.emplace_back(u,v,w);
		}
		else{
			adj[u].emplace_back(v, w);
			adj[v].emplace_back(u, w);
			sumW += w;
			dsu.unite(u, v);
		}
	}
	// dump(extra);

	if(x < sumW){
		cout << 0 << ln;
		return 0;
	}

	for(int u=1; u<=n; ++u){
		fill(seen+1, seen+n+1, false);
		explore(u, u, 0);
	}

	for(auto el: extra){
		int u,v,w; tie(u,v,w) = el;
		assert(maxW[u][v] > 0);
		LL addVal = w - maxW[u][v];
		// dump(maxW[u][v]);
		if(sumW + addVal == x) ++equ;
		else if(sumW + addVal > x) ++upper;
	}
	// dump(sumW);
	if(x == sumW){
		ans = mul(add(power(2,n-1), -2 + _MOD), power(2,m-(n-1)));
		_add(ans, mul(2, mul(add(power(2, equ), -1 + _MOD), power(2, upper))));
	}
	else if(x > sumW){
		// dump(equ, upper);
		ans = mul(2, mul(add(power(2, equ), -1 + _MOD), power(2, upper)));
	}
	else assert(false);

	cout << ans << ln;

}

Measured memory_bytes: 4352