There is a city park represented as a tree with n attractions as its vertices and n - 1 rails as its edges. The i-th attraction has happiness value a_i.

Each rail has a color. It is either black if t_i = 0, or white if t_i = 1. Black trains only operate on a black rail track, and white trains only operate on a white rail track. If you are previously on a black train and want to ride a white train, or you are previously on a white train and want to ride a black train, you need to use 1 ticket.

The path of a tour must be a simple path — it must not visit an attraction more than once. You do not need a ticket the first time you board a train. You only have k tickets, meaning you can only switch train types at most k times. In particular, you do not need a ticket to go through a path consisting of one rail color.

Define f(u, v) as the sum of happiness values of the attractions in the tour (u, v), which is a simple path that starts at the u-th attraction and ends at the v-th attraction. Find the sum of f(u,v) for all valid tours (u, v) (1 ≤ u ≤ v ≤ n) that does not need more than k tickets, modulo 10^9 + 7.

Input

The first line contains two integers n and k (2 ≤ n ≤ 2 ⋅ 10^5, 0 ≤ k ≤ n-1) — the number of attractions in the city park and the number of tickets you have.

The second line contains n integers a_1, a_2,…, a_n (0 ≤ a_i ≤ 10^9) — the happiness value of each attraction.

The i-th of the next n - 1 lines contains three integers u_i, v_i, and t_i (1 ≤ u_i, v_i ≤ n, 0 ≤ t_i ≤ 1) — an edge between vertices u_i and v_i with color t_i. The given edges form a tree.

Output

Output an integer denoting the total happiness value for all valid tours (u, v) (1 ≤ u ≤ v ≤ n), modulo 10^9 + 7.

Examples

Input


5 0
1 3 2 6 4
1 2 1
1 4 0
3 2 1
2 5 0


Output


45


Input


3 1
1 1 1
1 2 1
3 2 0


Output


10
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
const int N = 2e5 + 100;
const int MOD = 1e9 + 7;
int k, maxv, step = 0, ans = 0;
vector<int> lst;
int a[N], huprev[N], used[N], hap[N], col[N], sum[N];
vector<pair<int, int> > g[N];
int rmq_used[2][4 * N];
pair<int, int> rmq[2][4 * N];
void init() {}
void dfs1(int v, int pv, int cur_hap, int cur_col, int last_col, int cur_sum) {
  used[v] = step;
  huprev[v] = pv;
  hap[v] = cur_hap;
  col[v] = cur_col;
  sum[v] = cur_sum;
  if (pv != -1) {
    lst.push_back(v);
  }
  for (const pair<int, int>& e : g[v]) {
    if (used[e.first] != step) {
      if (cur_col == -1) {
        dfs1(e.first, (pv == -1 ? e.first : pv), (cur_hap + a[e.first]) % MOD,
             e.second, e.second, cur_sum);
      } else {
        dfs1(e.first, (pv == -1 ? e.first : pv), (cur_hap + a[e.first]) % MOD,
             cur_col, e.second, cur_sum + (e.second != last_col));
      }
    }
  }
}
pair<int, int> get(int c, int l, int r) {
  pair<int, int> res(0, 0);
  l += maxv;
  r += maxv;
  while (l <= r) {
    if (l % 2 != 0) {
      if (rmq_used[c][l] != step) {
        rmq[c][l] = make_pair(0, 0);
        rmq_used[c][l] = step;
      }
      res = make_pair((res.first + rmq[c][l].first) % MOD,
                      res.second + rmq[c][l].second);
    }
    l = (l + 1) / 2;
    if (r % 2 == 0) {
      if (rmq_used[c][r] != step) {
        rmq[c][r] = make_pair(0, 0);
        rmq_used[c][r] = step;
      }
      res = make_pair((res.first + rmq[c][r].first) % MOD,
                      res.second + rmq[c][r].second);
    }
    r = (r - 1) / 2;
  }
  return res;
}
void update(int c, int pos, pair<int, int> val) {
  pos += maxv;
  while (pos >= 1) {
    if (rmq_used[c][pos] != step) {
      rmq[c][pos] = make_pair(0, 0);
      rmq_used[c][pos] = step;
    }
    rmq[c][pos] = make_pair((rmq[c][pos].first + val.first) % MOD,
                            rmq[c][pos].second + val.second);
    pos /= 2;
  }
}
void solve(int v) {
  ++step;
  lst.clear();
  dfs1(v, -1, 0, -1, -1, 0);
  ans = (ans + a[v]) % MOD;
  int i = 0;
  while (i < ((int)(lst).size())) {
    int j = i;
    while (j + 1 < ((int)(lst).size()) &&
           huprev[lst[i]] == huprev[lst[j + 1]]) {
      ++j;
    }
    for (int z = i; z <= j; ++z) {
      if (sum[lst[z]] <= k) {
        ans = (ans + hap[lst[z]] + a[v]) % MOD;
      }
      pair<int, int> res = get(col[lst[z]], 0, k - sum[lst[z]]);
      ans = (ans + res.first + ll(res.second) * (a[v] + hap[lst[z]])) % MOD;
      res = get(col[lst[z]] ^ 1, 0, k - sum[lst[z]] - 1);
      ans = (ans + res.first + ll(res.second) * (a[v] + hap[lst[z]])) % MOD;
    }
    for (int z = i; z <= j; ++z) {
      update(col[lst[z]], sum[lst[z]], make_pair(hap[lst[z]], 1));
    }
    i = j + 1;
  }
  for (const pair<int, int>& e : g[v]) {
    g[e.first].erase(
        find((g[e.first]).begin(), (g[e.first]).end(), make_pair(v, e.second)));
    solve(e.first);
  }
}
void solve() {
  int n;
  scanf("%d %d", &n, &k);
  for (int i = 0; i < n; ++i) {
    scanf("%d", a + i);
  }
  for (int i = 0; i < n - 1; ++i) {
    int a, b, c;
    scanf("%d %d %d", &a, &b, &c);
    --a;
    --b;
    g[a].push_back(make_pair(b, c));
    g[b].push_back(make_pair(a, c));
  }
  maxv = 1;
  while (maxv < n) {
    maxv *= 2;
  }
  solve(0);
  printf("%d\n", ans);
}
int main() {
  init();
  int t = 1;
  for (int i = 0; i < t; ++i) {
    solve();
  }
  return 0;
}
