#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
#define N 2010
typedef long long ll;
template<typename T> inline void read(T &x) {
	x = 0; char c = getchar();
	while (!isdigit(c)) c = getchar();
	while (isdigit(c)) x = (x << 1) + (x << 3) + (c ^ 48), c = getchar();
}
using namespace std;
const int P = 1e9 + 7;
inline ll quickpow(ll x, int k) {
	ll res = 1;
	while (k) {
		if (k & 1)	res = res * x % P;
		x = x * x % P;
		k >>= 1;
	}
	return res;
}
int n, m;
ll X;
struct Edge{
	int u, v, w;
}E[N];
bool cmp(const Edge &a, const Edge &b) {
	return a.w < b.w;
}
int cnt, Cnt;
int fa[N];
int find(int cur) {
	return fa[cur] == cur ? cur : fa[cur] = find(fa[cur]);
}
inline ll calc(int id) {
	ll res = E[id].w;
	for (int i = 1; i <= n; ++i)	fa[i] = i;
	fa[E[id].u] = E[id].v;
	for (int i = 1, ct = 0; i <= m && ct < n - 1; ++i) if (i != id) {
		int u = E[i].u, v = E[i].v, w = E[i].w;
		u = find(u), v = find(v);
		if (u == v)	continue;
		fa[u] = v; res += w; ++ct;
	}
	return res;
}
int main() {
	read(n), read(m), read(X);
	for (int i = 1; i <= m; ++i) {
		int u, v, w; read(u), read(v), read(w);
		E[i] = (Edge){u, v, w};
	}
	sort(E + 1, E + 1 + m, cmp);
	ll mn = calc(0);
	if (mn > X) {
		puts("0");
		return 0;
	}
	for (int i = 1; i <= m; ++i) {
		ll tmp = calc(i);
//		printf("tmp = %lld\n", tmp);
		if (tmp > X)	++Cnt;
		else if (tmp == X)	++cnt;
	}
	if (mn == X) {
		printf("%lld\n", ((quickpow(2, cnt) - 2) * quickpow(2, Cnt) % P + P) % P);
		return 0;
	}
//	printf("cnt = %d, Cnt = %d\n", cnt, Cnt);
	ll ans = 2ll * (quickpow(2, cnt) - 1) * quickpow(2, Cnt) % P;
	printf("%lld\n", (ans % P + P) % P);
	return 0;
}
