// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
#define int ll
typedef ll Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
//#define mt make_tuple
//typedef tuple<int,int,int> tp;
//typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
//template<class C>constexpr int size(const C &c){return (int)c.size();}
//template<class T,size_t N> constexpr int size(const T (&xs)[N])noexcept{return (int)N;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
struct UnionFind{
    vector<int> data;
    UnionFind(int size) : data(size, -1) {}
    bool unionSet(int x,int y){
        x=root(x);y=root(y);
        if(x==y)return 0;
        if(data[y]<data[x])swap(x,y);
        data[x]+=data[y],data[y]=x;
        return 1;
    }
    bool findSet(int x,int y){
        return root(x)==root(y);
    }
    int root(int x){
        return data[x]<0 ? x : data[x]=root(data[x]);
    }
    int size(int x){
        return -data[root(x)];
    }
};
class DIJ{
	public:
	struct edge{
		int to,cost;
	};
	vector<vector<edge> >G;
	int n;
	vi d;//distance
	DIJ(int size){
		n=size;
		G=vector<vector<edge> >(n);
	}
	void add_edge(int a,int b,int c){
		edge e={b,c},ee={a,c};
		G[a].pb(e);
		G[b].pb(ee);
	}
	void dij(int s){
		d=vi(n,inf);
		d[s]=0;
		priority_queue<pii>q;
		q.push(pii(0,s));
		while(!q.empty()){
			pii p=q.top();
			q.pop();
			int pos=p.second,cost=-p.first;
			if(cost>d[pos])continue;
			rep(i,G[pos].size()){
				edge e=G[pos][i];
				int to=e.to;
				int nowcost=max(cost,e.cost);
				if(nowcost<d[to]){
					d[to]=nowcost;
					q.push(pii(-d[to],to));
				}
			}
		}
	}
};
map<pii,int>used;
class KRK{//c++11
	public:
	struct edge{
		int from,to,cost;
	};
	vector<edge>G;
	int n;
	KRK(int size){
		n=size;
	}
	void add_edge(int a,int b,int c){
		edge e={a,b,c};
		G.pb(e);
	}
	int krk(){
		int sum=0;
		sort(all(G),[](edge a,edge b){
			return a.cost<b.cost;
		});
		UnionFind uf(n);
		rep(i,G.size()){
			edge e=G[i];
			if(!uf.findSet(e.from,e.to)){
				sum+=e.cost;
				used[{e.from,e.to}]=1;
				uf.unionSet(e.from,e.to);
			}
		}
		return sum;
	}
};
int ma[1010][1010];
signed main(){
	int n,m,x;
	cin>>n>>m>>x;
	KRK krk(n);
	DIJ dij(n);
	vvi ed(m,vi(3));
	rep(i,m){
		int a,b,c;
		cin>>a>>b>>c;
		a--;b--;
		krk.add_edge(a,b,c);
		dij.add_edge(a,b,c);
		ed[i]={a,b,c};
	}
	ll s=krk.krk();
	
	rep(i,n){
		dij.dij(i);
		vi d=dij.d;
		rep(j,d.size())ma[i][j]=d[j];
//		rep(j,d.size())cout<<d[j]<<" ";cout<<endl;
	}
	int eq=0,up=0;
	rep(i,m)if(used[{ed[i][0],ed[i][1]}]==0){
		int t=ed[i][2]-ma[ed[i][0]][ed[i][1]];
		if(t==x-s)eq++;
		if(t>x-s)up++;
	}
	ll MOD=1000000007;
	vi po(2010,1);
	rep(i,2009)po[i+1]=po[i]*2%MOD;
	if(x<s)cout<<0<<endl;
	else if(x==s){
		ll out=0;
		(out+=(po[n-1]+MOD-2)*po[m-n+1]%MOD)%=MOD;
		(out+=2*(po[eq]+MOD-1)%MOD*po[up]%MOD)%=MOD;
		cout<<out<<endl;
	}else{
		ll out=0;
		(out+=2*(po[eq]+MOD-1)%MOD*po[up]%MOD)%=MOD;
		cout<<out<<endl;
	}
}









Measured memory_bytes: 8704