#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

#define all(c) (c).begin(),(c).end()
#define endl "\n"
#define ff first
#define ss second
#define allr(c) (c).rbegin(),(c).rend()
#define fr(x,in,n,r) for(ll x=in;x<n;x+=r)
#define ifr(x,n) for(ll x=0;x<n;x++)
#define dfr(x,n) for(ll x=n-1;x>=0;x--)
#define pb(a) push_back(a)
#define pf(a) push_front(a)
#define pof(a) pop_front(a)
#define pob(a) pop_back(a)
#define eb(a) emplace_back(a)
#define ef(a) emplace_front(a)
#define fstm(m,n,r) m.reserve(n);m.max_load_factor(r)
#define os tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
typedef long long ll;
typedef map<ll, ll> mll;
typedef map<string, ll> msll;
typedef unordered_map<ll, ll> umap;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;
typedef long double ld;
#define mod 1000000007
#define N 200005

vector<pll> v[N]; ll a[N];
bool vis[N];

void dfs(ll u) {
	vis[u] = 1;
	ifr(i, v[u].size()) {
		if (!vis[v[u][i].ff]) {
			a[v[u][i].ff] = a[u] ^ v[u][i].ss;
			dfs(v[u][i].ff);
		}
	}
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	// #ifndef ONLINE_JUDGE
	//  freopen("input.txt", "r", stdin);
	//  freopen("output.txt", "w", stdout);
	// #endif
	ll t = 1;
	// cin >> t;

	while (t--) {
		ll n, x, y, w;
		cin >> n;
		ifr(i, n - 1) {
			cin >> x >> y >> w;
			v[x].pb(pll(y, w));
			v[y].pb(pll(x, w));
		}
		a[1] = 0;
		dfs(1);
		ll ans = 0;
		ifr(i, 60) {
			ll cnt = 0, c = 0, r = 1ll << i;
			fr(j, 1, n + 1, 1) {
				if (r & (a[j]))cnt++;
				else c++;
			}
			ans = (ans + ((r) % mod * (cnt * c) % mod) % mod ) % mod;
		}
		cout << ans << endl;
	}

	return 0;
}
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <cstdio>
#include <limits>
#define rep(i,n) for(int i = 0; i < n; ++i)
#define rep1(i,n) for(int i = 1; i <= n; ++i)
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if(a < b){ a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if(a > b){ a = b; return 1; } return 0; }
template<class T> inline int  sz(T &a) { return a.size(); }
using ll = long long; using ld = long double;
using pi = pair<int,int>; using pl = pair<ll,ll>;
using vi = vector<int>; using vvi = vector<vi>;
using vl = vector<ll>; using vvl = vector<vl>;
const int inf = numeric_limits<int>::max();
const ll infll = numeric_limits<ll>::max();
int main()
{
  int n; cin >> n;
  ll x; cin >> x;
  vl a(n);
  rep(i,n) cin >> a[i];

  map<ll,ll> dp1;
  dp1[-x] = 1;
  for (int i = n-1; i >= 0; --i) {
    map<ll,ll> dp2;
    for(auto val: dp1) {
      auto [d, num] = val;
      if(abs(d) % a[i] != 0) {
	ll x1 = abs(d) / a[i];
	ll x2 = x1 + 1;
	ll c = - abs(d) / d;
	if(i != n - 1) {
	  if(x1 < a[i+1] / a[i]) dp2[d + c * x1 * a[i]] += num;
	  if(x2 < a[i+1] / a[i]) dp2[d + c * x2 * a[i]] += num;	  
	}
	else {
	  dp2[d + c * x1 * a[i]] += num;
	  dp2[d + c * x2 * a[i]] += num;	  	  
	}
      }
      else {
	dp2[0] += num;
      }
    }
    swap(dp1, dp2);
  }
  cout << dp1[0] << "\n";

  
  return 0;
}
