#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <cctype>
#include <cassert>
#include <limits>
#include <functional>
#include <iomanip>
#include <complex>
#include <bitset>

using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
#if defined(_MSC_VER) || __cplusplus > 199711L
#define aut(r,v) auto r = (v)
#else
#define aut(r,v) __typeof(v) r = (v)
#endif
#define each(it,o) for(aut(it, (o).begin()); it != (o).end(); ++ it)
#define all(o) (o).begin(), (o).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset(m,v,sizeof(m))
#define INF 0x3f3f3f3f3f3f3f3fLL
#define SIZE 8080
#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()

typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pair<int, int> > vpii; typedef long long ll;
typedef pair<int,ll> pill; typedef pair<ll,int> plli; 
typedef pair<double, int> pdi;
template<typename T, typename U> inline void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if(x < y) x = y; }
typedef complex<double> P;
ll MOD=1e9+7;
typedef ll Weight;
struct Edge {
	int src, dst;
	Weight weight;
};
bool operator < (const Edge &e, const Edge &f) {
	return e.weight != f.weight ? e.weight > f.weight : // !!INVERSE!!
	e.src != f.src ? e.src < f.src : e.dst < f.dst;
}
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

int N,M;
ll dp[114514]={0};
bool check[1005][1005];
ll Tree[1005][1005]={0};
ll Gra[1005][1005]={0};
vi Treev[1005];
pair<Weight, Edges> minimumSpanningTree(const Graph &g, int r = 0) {
	int n = g.size();
	Edges T;
	Weight total = 0;
	
	vector<bool> visited(n);
	priority_queue<Edge> Q;
	Edge hoge={-1, r, 0};
	Q.push( hoge );
	while (!Q.empty()) {
		Edge e = Q.top(); Q.pop();
		if (visited[e.dst]) continue;
		T.push_back(e);
		Tree[e.src][e.dst]=e.weight;
		Tree[e.dst][e.src]=e.weight;
		Treev[e.src].pb(e.dst);
		Treev[e.dst].pb(e.src);
		total += e.weight;
		visited[e.dst] = true;
		check[e.src][e.dst]=false;
		check[e.dst][e.src]=false;
		FOR(f, g[e.dst]) if (!visited[f->dst]) Q.push(*f);
	}
	return pair<Weight, Edges>(total, T);
}

bool visited[1145];
int kako[1145];
void dfs(int x){
	visited[x]=true;
	for(int i=0;i<Treev[x].size();i++){
		int ne = Treev[x][i];
		if(!visited[ne]){
			kako[ne]=x;
			dfs(ne);
		}
	}
}

ll pathmax(int a,int b){
	rep(i,N)visited[i]=false;
	kako[a] = a;
	dfs(a);
	int ne=kako[b],now=b;
	//cout<<a<<" "<<b<<"   "<<Gra[a][b]<<endl;
	vector<ll> vec;
	while(now != a){
		//cout<<ne<<" "<<now<<" "<<Tree[ne][now]<<endl;
		vec.pb(Tree[ne][now]);
		now = ne;
		ne = kako[now];
	}
	
	sort(vec.begin(),vec.end());
	reverse(vec.begin(),vec.end());
	return vec[0];
}

ll powMod(ll x, ll k, ll m) {//x^k (mod n)
	if (k == 0)     return 1;
	if (k % 2 == 0) return powMod(x*x % m, k/2, m);
	else            return x*powMod(x, k-1, m) % m;
}
int main(){
	cin>>N>>M;
	Weight X;
	cin>>X;
	rep(i,N)rep(j,N)check[i][j]=false;
	Graph Gph(N);
	for(int i=0;i<M;i++){
		int a,b;
		Weight c;
		cin>>a>>b>>c;a--;b--;
		Edge hen={a,b,c};
		Gph[a].pb(hen);
		Edge gen={b,a,c};
		Gph[b].pb(gen);
		check[a][b]=true;
		check[b][a]=true;
		Gra[a][b]=c;
		Gra[b][a]=c;
	}
	pair<Weight, Edges> data=minimumSpanningTree(Gph);
	ll ans=data.first;
	ll dif = X-ans;
	int eq=0,up=0;
	//cout<<ans<<endl;
	
	if(X>ans){
		for(int i=0;i<N;i++){
			for(int j=i+1;j<N;j++){
				bool X=false,Y=false;
				if(check[i][j]){
					ll hoge = Gra[i][j]-pathmax(i,j);
					if(dif<hoge)X=true;
					if(dif == hoge)Y=true;
				}
				if(X)up++;
				if(Y)eq++;
			}
		}
		//cout<<eq<<" "<<up<<endl;
		cout<<(2*(powMod((ll)2,(ll)eq,MOD)-(ll)1+MOD)%MOD)%MOD * (powMod((ll)2,(ll)up,MOD))%MOD<<endl;
		
	}else if(X==ans){
		for(int i=0;i<N;i++){
			for(int j=i+1;j<N;j++){
				bool X=false,Y=false;
				if(check[i][j]){
					ll hoge = Gra[i][j]-pathmax(i,j);
					if(dif<hoge)X=true;
					if(dif == hoge)Y=true;
				}
				if(X)up++;
				if(Y)eq++;
			}
		}
		//cout<<eq<<" "<<up<<endl;
		ll anss = (2*(powMod((ll)2,(ll)eq,MOD)-(ll)1+MOD)%MOD)%MOD * (powMod((ll)2,(ll)up,MOD))%MOD;
		anss = (anss + ((powMod((ll)2,N-1,MOD)-(ll)2 + MOD)%MOD * powMod((ll)2,M-N+1,MOD) )%MOD)%MOD;
		cout<<anss<<endl;
	}else{
		cout<<0<<endl;
	}
}

Measured memory_bytes: 17152