//teja349
#include <bits/stdc++.h>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <iomanip> 
//setbase - cout << setbase (16); cout << 100 << endl; Prints 64
//setfill -   cout << setfill ('x') << setw (5); cout << 77 << endl; prints xxx77
//setprecision - cout << setprecision (14) << f << endl; Prints x.xxxx
//cout.precision(x)  cout<<fixed<<val;  // prints x digits after decimal in val

using namespace std;
#define f(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) f(i,0,n)
#define fd(i,a,b) for(i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define vi vector< int >
#define vl vector< ll >
#define ss second
#define ff first
#define ll long long
#define pii pair< int,int >
#define pll pair< ll,ll >
#define sz(a) a.size()
#define inf (1000*1000*1000+5)
#define all(a) a.begin(),a.end()
#define tri pair<int,pii>
#define vii vector<pii>
#define vll vector<pll>
#define viii vector<tri>
#define mod (1000*1000*1000+7)
#define pqueue priority_queue< int >
#define pdqueue priority_queue< int,vi ,greater< int > >

//std::ios::sync_with_stdio(false); 
struct total{
	int u,v;
	ll w;
};  
ll n,m;
total edge[2123];
ll extra[2123][2123];
vector<vi> vec(1234);
ll dist[1234][12],paren[1234][12];
ll lev[1234],dsu[2234],x;
int cmp(total a,total b){
	return a.w<b.w;
}
int par(int u){
	//cout<<dsu[u]<<" "<<u<<endl;
	if(dsu[u]<0){
		return u;
	}
	dsu[u]=par(dsu[u]);
	return dsu[u];
}
int merge(int a,int b){
	a=par(a);
	b=par(b);
	if(a==b)
		return 0;
	if(dsu[a]>dsu[b]){
		swap(a,b);
	}
	//cout<<
	dsu[a]+=dsu[b];
	dsu[b]=a; 
	return 0;

}
int dfs(int cur,int pari){
	int i,u;
	paren[cur][0]=pari;
	if(pari==-1)
		lev[cur]=0;
	else
		lev[cur]=lev[pari]+1;

	rep(i,vec[cur].size()){
		u=(edge[vec[cur][i]].u)^cur^(edge[vec[cur][i]].v);
		if(u!=pari){
			dist[u][0]=edge[vec[cur][i]].w;
			dfs(u,cur);
		}
	}
	return 0;
}
int findmax(int u,int v){
	int i;
	ll ans=0;
	fd(i,11,0){
		if(lev[u]-(1<<i)>=lev[v]){
			ans=max(ans,dist[u][i]);
			u=paren[u][i];
		}
	}
	return ans;
}
int lca(int u,int v){
	if(lev[u]>lev[v])
		swap(u,v);
	int i;
	fd(i,11,0){
		if(lev[v]-(1<<i)>=lev[u]){
			v=paren[v][i];
		}
	}
	if(u==v)
		return u;
	fd(i,11,0){
		if(paren[u][i]!=paren[v][i]){
			u=paren[u][i];
			v=paren[v][i];
		}
	}
	return paren[u][0];
}
int getbest(int u,int v){
	int lc=lca(u,v);
	return max(findmax(u,lc),findmax(v,lc));
}
ll pre[2234];
ll buildspann(int a){
	int i,u,v,j;
	rep(i,n){
		dsu[i]=-1;
		vec[i].clear();
	}
	//cout<<"{dasd"<<a<<endl;
	ll ans=0;
	ll rere=edge[a].w;
	edge[a].w=0;
	if(par(edge[a].u)!=par(edge[a].v)){
		vec[edge[a].u].pb(a);
		vec[edge[a].v].pb(a);
		merge(edge[a].u,edge[a].v);
		ans+=rere;

	}
	//return 0;
	
	rep(i,m){
		pre[i]=0;
		if(i==a){
			pre[i]=1;
			continue;
		}
		u=edge[i].u;
		v=edge[i].v;
		if(par(u)!=par(v)){
			pre[i]=1;
			//cout<<a<<endl;
			merge(u,v);
			ans+=edge[i].w;
			vec[u].pb(i);
			vec[v].pb(i);
		}
		
	}
	
	//return 0;
	dfs(0,-1);
	f(j,1,12){
		rep(i,n){
			if(paren[i][j-1]!=-1){
				dist[i][j]=max(dist[i][j-1],dist[paren[i][j-1]][j-1]);
				paren[i][j]=paren[paren[i][j-1]][j-1];
			}
			else
				paren[i][j]=-1;
		}
	}
	rep(i,m){
		if(pre[i])
			continue;
		extra[a][i]=edge[i].w-getbest(edge[i].u,edge[i].v);
	}
	edge[a].w=rere;
	//cout<<ans<<endl;
	return ans;
}
ll two[2123];
int main(){
    std::ios::sync_with_stdio(false);
    
    cin>>n>>m;
    cin>>x;
    int i,j;
    rep(i,m){
    	cin>>edge[i].u>>edge[i].v>>edge[i].w;
    	edge[i].u--;
    	edge[i].v--;
    }
    two[0]=1;
    f(i,1,2123){
    	two[i]=two[i-1]*2;
    	two[i]%=mod;
    }
    ll val;
    sort(edge,edge+m,cmp);
    //return 0;
    rep(i,m){
    	val=buildspann(i);
    	//cout<<val<<" "<<i<<endl;
    	rep(j,m){
    		extra[i][j]+=val;
    	}
    }
    //return 0;
    rep(i,m){
    	dsu[i]=-1;
    }
    ll distinct=m;
    rep(i,m){
    	rep(j,m){
    		if(i==j){
    			continue;
    		}
    		if(extra[i][j]<x){
    			//cout<<"dsa"<<endl;
    			if(par(i)!=par(j)){
    				distinct--;
    				merge(i,j);
    			}
    		}
    	}
    }
    //cout<<distinct<<endl;
    ll baba=two[distinct];
    rep(i,m){
    	rep(j,m){
    		if(i==j)
    			continue;
    		if(extra[i][j]==x){
    			//cout<<"dqsad"<<endl;
    			if(par(i)!=par(j)){
    				//cout<<"Das";
    				distinct--;
    				merge(i,j);
    			}
    				
    		}
    	}
    }
    //cout<<two[distinct]<<endl;
    baba-=two[distinct];
    baba%=mod;
    baba+=mod;
    baba%=mod;
    cout<<baba<<endl;

    return 0;  
    
}



Measured memory_bytes: 35200