#include <stdio.h>
#include <algorithm>
#include <map>
#include <vector>
using namespace std;

const long long mod = 1000000007;
map<int, vector<pair<int, int> > > E,W;

int N,M,P[10010]; long long X;

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

int main()
{
	scanf ("%d %d %lld",&N,&M,&X);
	for (int i=0;i<M;i++){
		int x,y,c; scanf ("%d %d %d",&x,&y,&c);
		E[c].push_back({x,y});
	}

	for (int i=1;i<=N;i++) P[i] = i;

	int c = 0, d = 0, e = 0;
	long long mst = 0;
	for (auto &v : E){
		for (auto &p : v.second){
			if (find(p.first) != find(p.second)) c++;
			else{
				d++;
				W[v.first].push_back(p);
			}
		}

		for (auto &p : v.second){
			int x = find(p.first);
			int y = find(p.second);
			if (x != y){
				mst += v.first;
				P[x] = y;
			}
		}
	}

	long long ans = 1;
	if (X == mst){
		for (int i=0;i<c;i++) ans = ans * 2 % mod;
		ans = (ans + mod - 2) % mod;
		for (int i=0;i<d;i++) ans = ans * 2 % mod;
	}
	else{
		for (auto &v : W){
			for (auto &p : v.second){
				long long nmst = v.first;
				for (int i=1;i<=N;i++) P[i] = i;
				int x = find(p.first);
				int y = find(p.second);
				P[x] = y;

				for (auto &v : E){
					for (auto &p : v.second){
						int x = find(p.first);
						int y = find(p.second);
						if (x != y){
							P[x] = y;
							nmst += v.first;
						}
					}
				}

				if (nmst == X){
					d--;
					e++;
				}
				else if (nmst < X) d--;
			}
		}
		for (int i=0;i<e;i++) ans = ans * 2 % mod;
		ans = (ans + mod - 1) % mod;
		for (int i=0;i<=d;i++) ans = ans * 2 % mod;
	}
	printf ("%lld\n",ans);

	return 0;
}