#include <bits/stdc++.h>
using namespace std;
int v[1020304], __wowowow_[1020304], h[1020304], tot;
void add(int b, int e) {
  v[++tot] = e;
  __wowowow_[tot] = h[b];
  h[b] = tot;
  v[++tot] = b;
  __wowowow_[tot] = h[e];
  h[e] = tot;
}
int _id = 0;
int L[1020304], R[1020304];
int vis[1020304];
int fa[1020304][21], dep[1020304];
int lca(int x, int y) {
  if (dep[x] > dep[y]) swap(x, y);
  for (int j = 20; j >= 0; --j)
    if (dep[fa[y][j]] >= dep[x]) y = fa[y][j];
  if (x == y) return x;
  for (int j = 20; j >= 0; --j)
    if (fa[x][j] != fa[y][j]) x = fa[x][j], y = fa[y][j];
  return fa[x][0];
}
void dfs(int x) {
  vis[x] = true;
  L[x] = ++_id;
  for (int z = h[x]; z; z = __wowowow_[z])
    if (!vis[v[z]]) {
      dep[v[z]] = dep[x] + 1;
      dfs(v[z]);
      fa[v[z]][0] = x;
    }
  R[x] = _id;
}
void ins(int *tree, int x, int val) {
  for (int z = x; z <= 1000000; z += (z & (-z))) {
    tree[z] += val;
  }
}
int ask(int *tree, int r) {
  int ret = 0;
  for (int z = r; z; z -= (z & (-z))) {
    ret += tree[z];
  }
  return ret;
}
int up[1020304], down[1020304];
void dfs2(int x) {
  vis[x] = true;
  for (int z = h[x]; z; z = __wowowow_[z])
    if (!vis[v[z]]) {
      dfs2(v[z]);
      up[x] += up[v[z]];
      down[x] += down[v[z]];
    }
}
int n, K, B[1020304], E[1020304], W[1020304], treeL[1020304], treeR[1020304],
    treeAll[1020304], flag[1020304];
int pw2[1020304];
pair<int, int> paths[1020304], querys[1020304];
int main() {
  pw2[0] = 1;
  for (int i = 1; i <= 1000100; ++i)
    pw2[i] = (pw2[i - 1] + pw2[i - 1]) % 1000000007;
  cin >> n;
  for (int i = 1; i <= n - 1; ++i) {
    scanf("%d%d%d", &B[i], &E[i], &W[i]);
    add(B[i], E[i]);
  }
  _id = 0;
  memset(vis, 0, sizeof(vis[0]) * (n + 10));
  dfs(1);
  for (int T = 1; T <= 20; ++T)
    for (int i = 1; i <= n; ++i) fa[i][T] = fa[fa[i][T - 1]][T - 1];
  cin >> K;
  int cur = 1;
  memset(treeL, 0, sizeof(treeL[0]) * (n + 10));
  memset(treeR, 0, sizeof(treeL[0]) * (n + 10));
  memset(treeAll, 0, sizeof(treeL[0]) * (n + 10));
  for (int i = 1; i <= K; ++i) {
    int newPos;
    scanf("%d", &newPos);
    ins(treeL, L[cur], 1);
    ins(treeR, L[newPos], 1);
    paths[i] = make_pair(L[cur], L[newPos]);
    if (paths[i].first > paths[i].second) swap(paths[i].first, paths[i].second);
    int Lca = lca(cur, newPos);
    up[cur] += 1;
    up[Lca] -= 1;
    down[newPos] += 1;
    down[Lca] -= 1;
    cur = newPos;
  }
  memset(vis, 0, sizeof(vis[0]) * (n + 10));
  dfs2(1);
  int nQ = 0;
  int ans2 = 0;
  for (int i = 1; i <= n - 1; ++i)
    if (W[i]) {
      int cc = B[i];
      ++nQ;
      if (flag[nQ] = (L[cc] < L[E[i]])) cc = E[i];
      flag[nQ] ^= 1;
      querys[nQ] = make_pair(L[cc], R[cc]);
      int expo = flag[nQ] ? down[cc] : up[cc];
      (ans2 += (pw2[expo] - 1)) %= 1000000007;
    }
  sort(paths + 1, paths + K + 1);
  sort(querys + 1, querys + nQ + 1);
  for (int i = 1; i <= K; ++i) ins(treeAll, paths[i].second, 1);
  int pp = 0;
  int ans = 0;
  for (int i = 1; i <= nQ; ++i) {
    while (pp < K && paths[pp + 1].first < querys[i].first) {
      ++pp;
      ins(treeAll, paths[pp].second, -1);
    }
    int internal = ask(treeAll, querys[i].second);
    int all =
        flag[i]
            ? (ask(treeR, querys[i].second) - ask(treeR, querys[i].first - 1))
            : (ask(treeL, querys[i].second) - ask(treeL, querys[i].first - 1));
    int actually = all - internal;
    (ans += (pw2[actually] - 1)) %= 1000000007;
  }
  cout << ans2 << endl;
  return 0;
}
