# include <bits/stdc++.h>

/*
// ordered_set 
# include <ext/pb_ds/assoc_container.hpp>
# include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
# define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
*/
 
using namespace std;
 
typedef long long                                        ll;
typedef long double                                      ld;
typedef pair <int, int>                                  pii;
typedef pair <pii, int>                                  ppi;
typedef pair <int, pii>                                  pip;
typedef pair <pii, pii>                                  ppp;
typedef pair <ld, ld>                                    pll;
 
# define A                                               first
# define B                                               second
# define endl                                            '\n'
# define sep                                             ' '
# define all(x)                                          x.begin(), x.end()
# define kill(x)                                         return cout << x << endl, 0
# define SZ(x)                                           int(x.size())
# define Sort(x)                                         sort(all(x))
# define InTheNameOfGod                                  ios::sync_with_stdio(0);cin.tie(0); cout.tie(0);
 
ll power(ll a, ll b, ll md) {return (!b ? 1 : (b & 1 ? a * power(a * a % md, b / 2, md) % md : power(a * a % md, b / 2, md) % md));}

//const ll md = 1e9 + 7;//998244353;
const int xn = 2e3 + 10;
const int xm = 20 + 10;
const int SQ = 320;
const int sq = 320 + 10;
const int inf = 1e9 + 10;
const ll INF = 1e18 + 10;
const int MOD = 1e9 + 7;
const int TM = 3;
const int Base = 257;

int n, m, Par[xn], sz[xn], par[20][xn], ted, H[xn], cnt;
pair <ll, pii> E[xn];
ll X, MST, ans, W, mx[20][xn];
vector <pair <int, ll> > adj[xn];
vector <int> G[2][xn];
bool mark[xn];

int get_root(int v){
	if (Par[v] == v) return v;
	return get_root(Par[v]);
}
void merge(int v, int u, ll w){
	int vv = v, uu = u;
	v = get_root(v);
	u = get_root(u);
	if (v == u) return;
	MST += w;
	adj[vv].push_back({uu, w});
	adj[uu].push_back({vv, w});
	if (sz[u] > sz[v]) swap(v, u);
	Par[u] = v;
	sz[v] += sz[u];
}
void DFS3(int v){
	mark[v] = true;
	for (int u : G[0][v]) if (!mark[u]) DFS3(u);
	for (int u : G[1][v]) if (!mark[u]) DFS3(u);
}
void DFS2(int v){
	mark[v] = true;
	for (int u : G[0][v]) if (!mark[u]) DFS2(u);
}
void DFS(int v){
	mark[v] = true;
	for (pii u : adj[v]){
		if (mark[u.A]) continue;
		par[0][u.A] = v;
		mx[0][u.A] = u.B;
		H[u.A] = H[v] + 1;
		DFS(u.A);
	}
}
ll LCA(int v, int u){
	if (H[v] > H[u]) swap(v, u);
	ll MX = 0;
	int d = H[u] - H[v];
	for (int i = 12; i >= 0; -- i){
		if ((1 << i) > d) continue;
		MX = max(MX, mx[i][u]);
		u = par[i][u];
		d -= 1 << i;
	}
	if (v == u) return MX;
	for (int i = 12; i >= 0; -- i){
		if (par[i][v] == par[i][u]) continue;
		MX = max(MX, mx[i][v]);
		MX = max(MX, mx[i][u]);
		v = par[i][v];
		u = par[i][u];
	}
	MX = max(MX, mx[0][v]);
	MX = max(MX, mx[0][u]);
	return MX;
}

int main(){
    InTheNameOfGod;
    
    cin >> n >> m >> X;
    for (int i = 1; i <= m; ++ i)	cin >> E[i].B.A >> E[i].B.B >> E[i].A;
    sort(E + 1, E + m + 1);
    for (int i = 1; i <= m; ++ i){
    	for (int v = 1; v <= n; ++ v) Par[v] = v, sz[v] = 1, adj[v].clear();
    	MST = 0;
    	merge(E[i].B.A, E[i].B.B, E[i].A);
    	for (int j = 1; j <= m; ++ j) merge(E[j].B.A, E[j].B.B, E[j].A);
    	memset(mark, false, sizeof mark);
    	memset(par, 0, sizeof par);
    	memset(mx, 0, sizeof mx);
    	par[0][1] = 1, H[1] = 1;
    	DFS(1);
    	for (int j = 1; j < 13; ++ j){
    		for (int v = 1; v <= n; ++ v){
    			par[j][v] = par[j - 1][par[j - 1][v]];
    			mx[j][v] = max(mx[j - 1][v], mx[j - 1][par[j - 1][v]]);
			}
		}
    	ted = cnt = 0;
    	for (int j = i + 1; j <= m; ++ j){
    		W = MST - LCA(E[j].B.A, E[j].B.B) + E[j].A;
			if (W < X) G[0][i].push_back(j), G[0][j].push_back(i);
			if (W == X) G[1][i].push_back(j), G[1][j].push_back(i);
		}
	}
	memset(mark, false, sizeof mark);
	ted = 0;
	for (int i = 1; i <= m; ++ i) if (!mark[i]) DFS2(i), ++ ted;
	ans = power(2, ted, MOD);
	memset(mark, false, sizeof mark);
	ted = 0;
	for (int i = 1; i <= m; ++ i) if (!mark[i]) DFS3(i), ++ ted;
	ans = (ans - power(2, ted, MOD) + MOD) % MOD;
	cout << ans << endl;
	
    return 0;
}


Measured memory_bytes: 18944