#include <bits/stdc++.h> 
using namespace std;

#define sz(x) (int)x.size() 
#define pb push_back 
#define mp make_pair 
#define fi(a, b) for(int i=a; i<=b; i++) 
#define fj(a, b) for(int j=a; j<=b; j++) 
#define fo(a, b) for(int o=a; o<=b; o++) 
#define fdi(a, b) for(int i=a; i>=b; i--) 
#define fdj(a, b) for(int j=a; j>=b; j--) 
#define fdo(a, b) for(int o=a; o>=b; o--) 

#ifdef LOCAL
#define err(...) fprintf(stderr, __VA_ARGS__)
#else
#define err(...) while(false) {}
#endif

typedef long long ll; 
typedef pair<int, int> pii; 
typedef pair<ll, ll> pll; 
typedef vector<int> vi; 
typedef vector<pii> vpii; 
typedef vector<pll> vpll; 
typedef long double ld;

/////////////////////////////////

int const MAX = 2000 + 41;
int const MOD = 1000 * 1000 * 1000 + 7;

int add(int a, int b) {
	return (a + b) % MOD; 
}

int sub(int a, int b) {
	a -= b;
	while (a < 0) a += MOD;
	return a;
}

int mult(int a, int b) {
	return (int) ( (ll) a * b % MOD);
}

int n, m;
ll x;
int ans;
int p2[MAX];

struct Edge {
	int u, v, w;
	Edge() {};
	Edge(int u, int v, int w) : u(u), v(v), w(w) {};
	bool operator<(const Edge &a) const {
		return w < a.w;
	};
};

vector<Edge> e;

namespace Dsu {
	int par[MAX], q[MAX];
	
	void init() {
		fi(0, MAX - 1) {
			par[i] = i;
			q[i] = 1;
		}
	}

	int find(int x) {
		if (x == par[x]) return x;
		return par[x] = find(par[x]);
	}

	bool check(int a, int b) {
		a = find(a);
		b = find(b);
		if (a == b) return false;
		return true;
	}

	void uni(int a, int b) {
		a = find(a);
		b = find(b);
		if (q[a] < q[b]) swap(a, b);
		q[a] += q[b];
		par[b] = a;
	}
};

void solve1() {//>
	ll sum = 0;
	Dsu::init();
	fi(0, sz(e) - 1) {
		if (Dsu::check(e[i].u, e[i].v)) {
			Dsu::uni(e[i].u, e[i].v);
			sum += e[i].w;
		}
	}	
	if (sum > x) {
		printf("0\n");
		err("solve1\n");
		exit(0);
	}
}

void solve2() {//==
	ll sum = 0;
	Dsu::init();
	fi(0, sz(e) - 1) {
		if (Dsu::check(e[i].u, e[i].v)) {
			Dsu::uni(e[i].u, e[i].v);
			sum += e[i].w;
		}
	}		
	if (sum < x) return;
	Dsu::init();
	vi f(m, 0);
	fi(0, sz(e) - 1) {
		fj(i, sz(e) - 1) {
			if (e[j].w > e[i].w) break;
			if (Dsu::check(e[j].u, e[j].v)) {
				f[j] = 1;
			}
		}
		if (Dsu::check(e[i].u, e[i].v)) {
			Dsu::uni(e[i].u, e[i].v);
		}
	}
	int q = 0;
	fi(0, sz(f) - 1) {
		q += f[i];
	}
	ans = p2[m];		
	ans = sub(ans, p2[m - q + 1]);
	printf("%d\n", ans);
	err("solve2\n");
	exit(0);
}

void solve3() {//<
	int q2 = 0;
	Dsu::init();
	vi f(m, 0);
	fi(0, sz(e) - 1) {
		fj(i, sz(e) - 1) {
			if (e[j].w > e[i].w) break;
			if (Dsu::check(e[j].u, e[j].v)) {
				f[j] = 1;
			}
		}
		if (Dsu::check(e[i].u, e[i].v)) {
			Dsu::uni(e[i].u, e[i].v);
		}
	}
	fi(0, sz(f) - 1) {
		q2 += f[i];
	}

	int qs = 0;
	int ql = 0;
	int qg = 0;
	fi(0, sz(e) - 1) {
		if (f[i]) continue;
		Dsu::init();
		Dsu::uni(e[i].u, e[i].v);
		ll sum = e[i].w;
		fj(0, sz(e) - 1) {
			if (Dsu::check(e[j].u, e[j].v)) {
				Dsu::uni(e[j].u, e[j].v);
				sum += e[j].w;
			}		
		}
		if (sum == x) {
			qs++;
		} else if (sum < x) {
			ql++;
		} else {
			qg++;
		}
	}

	int v1 = p2[qs];
	v1 = sub(v1, 1);
	int v2 = p2[qg];
	int v3 = 2;
	ans = mult(v1, mult(v2, v3));
	printf("%d\n", ans);
	err("solve3\n");	
}

void solve() {
	p2[0] = 1;
	fi(1, MAX - 1) {
		p2[i] = mult(p2[i - 1], 2);
	}
	sort(e.begin(), e.end());
	solve1();
	solve2();
	solve3();
}

int main() {
#ifdef LOCAL
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	scanf("%d %d", &n, &m);
	scanf("%lld", &x);
	fi(1, m) {
		int u, v, w;
		scanf("%d %d %d", &u, &v, &w);
		e.pb(Edge(u, v, w));
	}
	solve();		

	
#ifdef LOCAL
	err("ELAPSED TIME: %.3Lf\n", (ld) clock() / CLOCKS_PER_SEC);
#endif	
	
	return 0;
}

Measured memory_bytes: 384