#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "functional"
#include "ctime"

using namespace std;

//constexpr long long int MOD = 1000000007;
constexpr int MOD = 1000000007;
//constexpr int MOD = 998244353;
//constexpr long long int MOD = 998244353;
constexpr double EPS = 1e-8;

//int N, M, K, H, W, L, R;
long long int N, M, K, H, W, L, R;

class UnionFind {
	vector<int>parent;
	vector<int>rank;
public:
	UnionFind(int num) {
		num++;
		parent.resize(num);
		rank.resize(num);
		for (int i = 0; i < num; i++) {
			parent[i] = i;
			rank[i] = 0;
		}
	}
	int Find(int node) {
		if (parent[node] == node)return node;
		else return parent[node] = Find(parent[node]);
	}
	void Unite(int u, int v) {
		u = Find(u);
		v = Find(v);
		if (u == v)return;
		if (rank[u] < rank[v])parent[u] = v;
		else {
			parent[v] = u;
			if (rank[u] == rank[v])rank[u]++;
		}
	}
	bool Check_Same(int u, int v) {
		return Find(u) == Find(v);
	}
};

struct Edge {
	int a, b;
	long long int cost;
	Edge(const int aa, const int bb, const int cc) {
		a = aa, b = bb, cost = cc;
		return;
	}
	bool operator <(const Edge&e)const {
		return cost < e.cost;
	}
};

struct MST_Edge {
	int to, cost;
	MST_Edge(const int a, const int b) {
		to = a, cost = b;
		return;
	}
};

long long int power(long long int x, long long int n, long long int M) {
	long long int ret = 1;
	long long int by = x;
	while (n) {
		if (n & 1) {
			ret *= by;
			ret %= M;
		}
		by *= by;
		by %= M;
		n >>= 1;
	}
	return ret;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);

	cin >> N >> M;
	long long int X;
	cin >> X;
	vector<Edge>edge;
	for (int i = 0; i < M; i++) {
		cin >> L >> R >> K;
		L--;
		R--;
		edge.push_back(Edge(L, R, K));
	}
	sort(edge.begin(), edge.end());
	vector<vector<MST_Edge>>mst_edge(N);
	UnionFind uf(N);
	K = 0;
	vector<int>used(M);
	int cnt = -1;
	for (auto i : edge) {
		cnt++;
		if (uf.Check_Same(i.a, i.b))continue;
		used[cnt] = 1;
		mst_edge[i.a].push_back(MST_Edge(i.b, i.cost));
		mst_edge[i.b].push_back(MST_Edge(i.a, i.cost));
		K += i.cost;
		uf.Unite(i.a, i.b);
	}
	if (K > X) {
		cout << 0 << endl;
		return 0;
	}
	vector<vector<int>>dp(N, vector<int>(N, -1));
	for (int i = 0; i < N; i++) {
		dp[i][i] = 0;
		queue<int>Q;
		Q.push(i);
		while (!Q.empty()) {
			int cn = Q.front();
			Q.pop();
			for (auto j : mst_edge[cn]) {
				if (dp[i][j.to]==-1) {
					dp[i][j.to] = max(dp[i][cn],j.cost);
					Q.push(j.to);
				}
			}
		}
	}
	int eq = 0;
	int ov = 0;
	cnt = -1;
	for (auto i : edge) {
		cnt++;
		if (used[cnt])continue;
		if (K + i.cost - dp[i.a][i.b] == X)eq++;
		if (K + i.cost - dp[i.a][i.b] > X)ov++;
	}
	if (X == K) {
		//assert(0);
		long long int ans = 1;
		ans = power(2, N - 1 + eq, MOD) + MOD - 2;
		ans %= MOD;
		ans *= power(2, ov, MOD);
		ans %= MOD;
		cout << ans << endl;
	}
	else {
		long long int ans = 2;
		ans *= power(2, ov, MOD);
		ans %= MOD;
		ans *= power(2, eq, MOD) + MOD - 1;
		ans %= MOD;
		cout << ans << endl;
	}
	//cout << eq << " " << ov << endl;
	//cout << K << endl;
}

Measured memory_bytes: 4352