#include <bits/stdc++.h>

#define x first
#define y second
#define y1 Y1
#define y2 Y2
#define mp make_pair
#define pb push_back
#define DEBUG(x) cout << #x << " = " << x << endl;

using namespace std;

typedef long long LL;
typedef pair <int, int> pii;

template <typename T> inline int Chkmax (T &a, T b) { return a < b ? a = b, 1 : 0; }
template <typename T> inline int Chkmin (T &a, T b) { return a > b ? a = b, 1 : 0; }
template <typename T> inline T read ()
{
	T sum = 0, fl = 1; char ch = getchar();
	for (; !isdigit(ch); ch = getchar()) if (ch == '-') fl = -1;
	for (; isdigit(ch); ch = getchar()) sum = (sum << 3) + (sum << 1) + ch - '0';
	return sum * fl;
}

inline void proc_status ()
{
	ifstream t ("/proc/self/status");
	cerr << string (istreambuf_iterator <char> (t), istreambuf_iterator <char> ()) << endl;
}

const int Maxn = 2000 + 100;
const int Mod = 1e9 + 7;

namespace MATH
{
	int fac[Maxn], ifac[Maxn];

	inline void Add (int &a, int b) { if ((a += b) >= Mod) a -= Mod; }

	inline int Pow (int a, int b)
	{
		int ans = 1;
		for (int i = b; i; i >>= 1, a = (LL) a * a % Mod) if (i & 1) ans = (LL) ans * a % Mod;
		return ans;
	}

	inline void init (int n = 2000)
	{
		fac[0] = 1;
		for (int i = 1; i <= n; ++i) fac[i] = (LL) fac[i - 1] * i % Mod;
		ifac[n] = Pow (fac[n], Mod - 2);
		for (int i = n - 1; i >= 0; --i) ifac[i] = (LL) ifac[i + 1] * (i + 1) % Mod;
	}

	inline int C (int n, int m) { if (n < m) return 0; return (LL) fac[n] * ifac[m] % Mod * ifac[n - m] % Mod; }
}

using namespace MATH;

int N, M;
LL X;
struct edge
{
	int x, y, z;
} E[Maxn];

inline int cmp (edge a, edge b) { return a.z < b.z; }

namespace DSU
{
	int fa[Maxn];

	inline void init () { for (int i = 1; i <= N; ++i) fa[i] = i; }
	inline int get_fa (int x) { return fa[x] == x ? x : fa[x] = get_fa (fa[x]); }
	inline int check (int x, int y) { return get_fa (x) == get_fa (y); }
	inline void link (int x, int y) { fa[get_fa (x)] = get_fa (y); }
}

int Vis[Maxn];

inline void Solve ()
{
	sort (E + 1, E + M + 1, cmp);

	DSU :: init ();
	LL sum = 0;
	for (int i = 1; i <= M; ++i)
	{
		int x = E[i].x, y = E[i].y, z = E[i].z;
		if (!DSU :: check (x, y))
		{
			Vis[i] = 1;
			DSU :: link (x, y);
			sum += z;
		}
	}
	
	if (sum > X) return void (puts("0"));
	if (sum == X)
	{
		int ans = (Pow (2, M) - 2ll * Pow (2, M - (N - 1)) % Mod + Mod) % Mod;
		int prob = 0;

		for (int t = 1; t <= M; ++t)
		{
			if (Vis[t]) continue;
			DSU :: init ();
			DSU :: link (E[t].x, E[t].y);
			LL now = E[t].z;
			int cnt = 0;
			for (int i = 1; i <= M; ++i)
			{
				int x = E[i].x, y = E[i].y, z = E[i].z;
				if (!DSU :: check (x, y))
				{
					if (!Vis[i]) ++cnt;
					DSU :: link (x, y);
					now += z;
				}
			}

			if (cnt > 1 || now != X) continue;

			++prob;
		}

		Add (ans, 2ll * (Pow (2, M - (N - 1)) - Pow (2, M - (N - 1) - prob) + Mod) % Mod);
		cout << ans << endl;
	}
	else
	{
		int prob = 0, ban = 0;

		for (int t = 1; t <= M; ++t)
		{
			if (Vis[t]) continue;
			DSU :: init ();
			DSU :: link (E[t].x, E[t].y);
			LL now = E[t].z;
			int cnt = 0;
			for (int i = 1; i <= M; ++i)
			{
				int x = E[i].x, y = E[i].y, z = E[i].z;
				if (!DSU :: check (x, y))
				{
					if (!Vis[i]) ++cnt;
					DSU :: link (x, y);
					now += z;
				}
			}

			if (now < X) ++ban;
			if (now != X) continue;

			++prob;
		}

		int ans = 0;
		Add (ans, 2ll * (Pow (2, M - (N - 1) - ban) - Pow (2, M - (N - 1) - ban - prob) + Mod) % Mod);
		cout << ans << endl;

	}
}

inline void Input ()
{
	N = read<int>(), M = read<int>();
	X = read<LL>();
	for (int i = 1; i <= M; ++i) E[i].x = read<int>(), E[i].y = read<int>(), E[i].z = read<int>();
}

int main()
{

#ifdef hk_cnyali
	freopen("E.in", "r", stdin);
	freopen("E.out", "w", stdout);
#endif

	Input ();
	Solve ();

	return 0;
}


Measured memory_bytes: 256