#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;

int p[1100];
int root(int x){
	if(p[x] == x) return x;
	return p[x] = root(p[x]);
}
void merge(int a, int b){
	a = root(a); b = root(b);
	if(a != b) p[b] = a;
}
const int mod = 1e9 + 7;
ll two[2100];

int rec(int c, int d, vi &vis, const vector<vector<tuple<int,int,int>>> &g, const vi &flag){
	vis[c] = 1;
	for(auto i : g[c]){
		int to, w, id; tie(to, w, id) = i;
		if(vis[to] || !flag[id]) continue;
		if(to == d) return w;
		int x = rec(to, d, vis, g, flag);
		if(x > 0) return max(x, w);
	}
	return 0;
}

int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	two[0] = 1;
	rep(i, 2099) two[i + 1] = two[i] * 2 % mod;
	
	int n, m; ll x;
	cin >> n >> m >> x;
	vector<pair<int,pi>> e;
	vector<vector<tuple<int,int,int>>> g(n);
	rep(i, m){
		int a, b, c; cin >> a >> b >> c; a--; b--;
		e.emplace_back(c, pi(a, b));
	}
	sort(all(e));
	rep(i, m){
		int a = e[i].second.first, b = e[i].second.second, c = e[i].first;
		g[a].emplace_back(b, c, i);
		g[b].emplace_back(a, c, i);
	}
	
	if(n < 3){
		cout << 0 << endl;
		return 0;
	}
	rep(i, n) p[i] = i;
	
	ll sum = 0;
	int used = 0, usable = 0;
	vi flag(m);
	
	rep(i, m){
		int k = 0;
		vi use;
		for(int j = i; j < m && e[i].first == e[j].first; j++, k++){
			int a = root(e[j].second.first);
			int b = root(e[j].second.second);
			if(a == b) continue;
			use.pb(j);
			usable++;
		}
		
		for(auto j : use){
			int a = e[j].second.first;
			int b = e[j].second.second;
			if(root(a) == root(b)) continue;
			merge(a, b);
			flag[j] = 1;
			sum += e[j].first;
			if(++used == n - 1){
				if(sum > x){
					cout << 0 << endl;
					return 0;
				}
				if(sum == x){
					ll ans = (two[usable] + mod - 2) * two[m - usable] % mod;
					cout << ans << endl;
					return 0;
				}
				break;
			}
		}
		i += k - 1;
	}
	dbg(x, sum);
	//for(auto i : e) dbg(i);
	
	int eq = 0, bigger = 0;
	rep(i, m) if(!flag[i]){
		vi vis(n);
		int a = e[i].second.first, b = e[i].second.second;
		int diff = e[i].first - rec(a, b, vis, g, flag);
		
		if(sum + diff == x) eq++;
		else if(sum + diff > x) bigger++;
	}
	dbg(eq, bigger);
	
	ll ans = 2 * (two[eq] + mod - 1) % mod * two[bigger] % mod;
	cout << ans % mod << endl;
	return 0;
}

Measured memory_bytes: 512