#include<bits/stdc++.h>
#define mod 1000000007
#define int long long
using namespace std;
int n, m, v, res = 1, f[1007];
pair<int, pair<int, int> >e[2007];
int read()
{
	int num = 0;
	char c = getchar();
	while (c < '0' || c>'9')c = getchar();
	while (c >= '0' && c <= '9')num = num * 10 + c - '0', c = getchar();
	return num;
}
int find(int x)
{
	if (f[x] == x)return x;
	return f[x] = find(f[x]);
}
int merge(pair<int, int>x)
{
	int a = find(x.first), b = find(x.second);
	if (f[a] == f[b])return 0;
	f[a] = b;
	return 1;
}
int kruskal(int x)
{
	for (int i = 1; i <= n; i++)
		f[i] = i;
	int res = 0;
	if (x)res += merge(e[x].second) * e[x].first;
	for (int i = 1; i <= m; i++)
		res += merge(e[i].second) * e[i].first;
	return res;
}
int fpow(int a, int x)
{
	int res = 1;
	while (x)
	{
		if (x & 1)res = 1LL * res * a % mod;
		a = 1LL * a * a % mod;
		x >>= 1;
	}
	return res;
}
signed main()
{
	n = read();
	m = read();
	v = read();
	for (int i = 1; i <= m; i++)
	{
		e[i].second.first = read();
		e[i].second.second = read();
		e[i].first = read();
	}
	sort(e + 1, e + m + 1);
	int ans = kruskal(0);
	if (ans > v)cout << 0 << endl;
	else if (ans == v)
	{
		int cnt1 = 0, cnt2 = 0;
		for (int i = 1; i <= m; i++)
			if (kruskal(i) == ans)cnt1++;
			else cnt2++;
		res = 1LL * ((fpow(2, cnt1) - 2 + mod) % mod) * fpow(2, cnt2) % mod;
		cout << res << endl;
	}
	else
	{
		int cnt1 = 0, cnt2 = 0;
		for (int i = 1; i <= m; i++)
		{
			int ch = kruskal(i);
			if (ch == v)cnt1++;
			if (ch > v)cnt2++;
		}
		res = 2LL * ((fpow(2, cnt1) - 1 + mod) % mod) * fpow(2, cnt2) % mod;
		cout << res << endl;
	}
	return 0;
}