#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > E[100000 + 5];
int par[100000 + 5][20], h[100000 + 5];
int goUp[100000 + 5], goDown[100000 + 5];
int n;
int mod = 1e9 + 7;
int lca(int u, int v) {
  if (h[u] < h[v]) swap(u, v);
  for (int log = 17; log >= 0; log--)
    if (h[par[u][log]] >= h[v]) u = par[u][log];
  for (int log = 17; log >= 0; log--)
    if (par[u][log] != par[v][log]) {
      u = par[u][log];
      v = par[v][log];
    }
  while (u != v) {
    u = par[u][0];
    v = par[v][0];
  }
  return u;
}
void dfs(int u) {
  for (int i = 0; i < E[u].size(); i++) {
    int c = E[u][i].second;
    int v = E[u][i].first;
    if (par[u][0] == v) continue;
    par[v][0] = u;
    h[v] = h[u] + 1;
    dfs(v);
  }
}
void upd(int u, int v) {
  int w = lca(u, v);
  if (w != u && w != v) {
    goUp[u]++;
    goUp[w]--;
    goDown[v]++;
    goDown[w]--;
  } else if (w == u) {
    goDown[v]++;
    goDown[u]--;
  } else {
    goUp[u]++;
    goUp[v]--;
  }
}
void load_graph() {
  scanf("%d", &n);
  for (int i = 1; i < n; i++) {
    int u, v, c;
    scanf("%d %d %d", &u, &v, &c);
    if (c == 0) {
      E[u].push_back(pair<int, int>(v, 3));
      E[v].push_back(pair<int, int>(u, 3));
    } else {
      E[u].push_back(pair<int, int>(v, 1));
      E[v].push_back(pair<int, int>(u, 2));
    }
  }
}
int ans = 0;
int pw2[10 * 100000 + 5];
void final_dfs(int u) {
  for (int i = 0; i < E[u].size(); i++) {
    int v = E[u][i].first;
    int c = E[u][i].second;
    if (v == par[u][0]) continue;
    final_dfs(v);
    goDown[u] += goDown[v];
    goUp[u] += goUp[v];
    if (c == 1) {
      ans = (ans + pw2[goUp[v]] - 1) % mod;
      if (ans < 0) ans += mod;
    }
    if (c == 2) {
      ans = (ans + pw2[goDown[v]] - 1) % mod;
      if (ans < 0) ans += mod;
    }
  }
}
void prepare() {
  h[1] = 1;
  dfs(1);
  for (int log = 1; log <= 17; log++)
    for (int u = 1; u <= n; u++) par[u][log] = par[par[u][log - 1]][log - 1];
  pw2[0] = 1;
  for (int i = 1; i <= 10 * 100000; i++) pw2[i] = (1ll * pw2[i - 1] * 2 % mod);
}
int c[100000 * 10 + 22];
int main() {
  load_graph();
  prepare();
  int k;
  scanf("%d", &k);
  for (int i = 1; i <= k; i++) scanf("%d", &c[i]);
  c[0] = 1;
  for (int i = 1; i <= k; i++) upd(c[i - 1], c[i]);
  final_dfs(1);
  printf("%d", ans);
}
