#include <iostream>
#include <algorithm>
#include <utility>
#include <numeric>
#include <vector>
#include <array>

class union_find {
private:
  size_t component;
  std::vector<int32_t> parent;

public:
  union_find() = default;
  union_find(size_t size_) { init(size_); }

  void init(size_t size_) {
    component = size_;
    parent.assign(size_, -1);
  }

  size_t count_components() const { 
    return component; 
  }
  size_t component_size(size_t i) { 
    return -parent[find_parent(i)]; 
  }
  bool same_component(size_t i, size_t j) { 
    return find_parent(i) == find_parent(j); 
  }

  size_t find_parent(size_t i) {
    if (parent[i] < 0) {
      return i;
    }
    else {
      return parent[i] = find_parent(parent[i]);
    }
  }

  bool unite(size_t i, size_t j) {
    i = find_parent(i);
    j = find_parent(j);
    if (i == j) {
      return false;
    }
    if (parent[i] > parent[j]) {
      std::swap(i, j);
    }
    parent[i] += parent[j];
    parent[j] = i;
    --component;
    return true;
  }

};

template <uint32_t Modulus>
class modular {
public:
  using value_type = uint32_t;
  using max_type = uint64_t;

  static constexpr value_type mod = Modulus;
  static constexpr value_type get_mod() { return mod; }
  static_assert(mod >= 2, "invalid mod :: smaller than 2");
  static_assert(mod < (value_type(1) << 31), "invalid mod :: over 2^31");

  template <class T>
  static constexpr value_type normalize(T value_) {
    if (value_ < 0) {
      value_ = -value_;
      value_ %= mod;
      if (value_ == 0) return 0;
      return mod - value_;
    }
    return value_ % mod;
  }

private:
  value_type value;

public:
  constexpr modular(): value(0) { }
  template <class T>
  explicit constexpr modular(T value_): value(normalize(value_)) { }
  template <class T>
  explicit constexpr operator T() { return static_cast<T>(value); }

  constexpr value_type get() const { return value; }
  constexpr modular operator - () const { return modular(mod - value); }
  constexpr modular operator ~ () const { return inverse(); }

  constexpr value_type &extract() { return value; }
  constexpr modular inverse() const { return power(mod - 2); }
  constexpr modular power(max_type exp) const {
    modular res(1), mult(*this);
    while (exp > 0) {
      if (exp & 1) res *= mult;
      mult *= mult;
      exp >>= 1;
    }
    return res;
  }

  constexpr modular operator + (const modular &rhs) const { return modular(*this) += rhs; }
  constexpr modular& operator += (const modular &rhs) { 
    if ((value += rhs.value) >= mod) value -= mod; 
    return *this; 
  }

  constexpr modular operator - (const modular &rhs) const { return modular(*this) -= rhs; }
  constexpr modular& operator -= (const modular &rhs) { 
    if ((value += mod - rhs.value) >= mod) value -= mod; 
    return *this; 
  }

  constexpr modular operator * (const modular &rhs) const { return modular(*this) *= rhs; }
  constexpr modular& operator *= (const modular &rhs) { 
    value = (max_type) value * rhs.value % mod;
    return *this;
  }

  constexpr modular operator / (const modular &rhs) const { return modular(*this) /= rhs; }
  constexpr modular& operator /= (const modular &rhs) { return (*this) *= rhs.inverse(); }

  constexpr bool zero() const { return value == 0; }
  constexpr bool operator == (const modular &rhs) const { return value == rhs.value; }
  constexpr bool operator != (const modular &rhs) const { return value != rhs.value; }
  friend std::ostream& operator << (std::ostream &stream, const modular &rhs) {
    return stream << rhs.value;
  }

};

using m32 = modular<1000000007>;

using i32 = int32_t;
using i64 = int64_t;
using u32 = uint32_t;
using u64 = uint64_t;

constexpr i32 inf32 = (i32(1) << 30) - 1;
constexpr i64 inf64 = (i64(1) << 62) - 1;

int main() {
  size_t N, M;
  std::cin >> N >> M;
  i64 X;
  std::cin >> X;
  std::vector<i32> U(M), V(M), W(M);
  for (size_t i = 0; i < M; ++i) {
    std::cin >> U[i] >> V[i] >> W[i];
    --U[i]; --V[i];
  }
  std::vector<size_t> order(M);
  std::iota(order.begin(), order.end(), 0);
  std::sort(order.begin(), order.end(), [&](size_t i, size_t j) {
    return W[i] < W[j];
  });
  std::vector<i64> S(M);
  for (size_t i = 0; i < M; ++i) {
    union_find dsu(N);
    dsu.unite(U[i], V[i]);
    S[i] += W[i];
    for (auto j: order) {
      if (dsu.unite(U[j], V[j])) {
        S[i] += W[j];
      }
    }
  }
  std::sort(S.begin(), S.end());
  i32 x = std::lower_bound(S.cbegin(), S.cend(), X) - S.cbegin();
  i32 y = std::upper_bound(S.cbegin(), S.cend(), X) - S.cbegin();
  std::cout << m32(2).power(M - x + (x > 0)) - m32(2).power(M - y + (y > 0)) << '\n';
  return 0;
}


Measured memory_bytes: 256