#include <bits/stdc++.h>
using namespace std;
const int MAXN = 101 * 1001, MOD = 1e9 + 7;
vector<pair<int, int> > a[MAXN];
int q[MAXN] = {}, w[MAXN], e[MAXN] = {}, is[MAXN] = {};
long long t2[MAXN * 10] = {}, par[MAXN][20] = {}, t[MAXN] = {};
int dp[MAXN] = {}, dp2[MAXN] = {};
void dfs(int u, int p) {
  par[u][0] = p;
  for (int i = 1; i < 20; i++) par[u][i] = par[par[u][i - 1]][i - 1];
  for (auto v : a[u]) {
    if (v.first == p) continue;
    is[v.first] = v.second;
    t[v.first] = t[u] + 1;
    dfs(v.first, u);
  }
}
inline int get_par(int x, int y) {
  for (int i = 0; i < 20; i++)
    if (y & (1 << i)) x = par[x][i];
  return x;
}
inline int lca(int x, int y) {
  if (t[x] > t[y]) swap(x, y);
  y = get_par(y, t[y] - t[x]);
  if (x == y) return x;
  for (int i = 19; i > -1; i--) {
    if (par[x][i] != par[y][i]) {
      x = par[x][i];
      y = par[y][i];
    }
  }
  return par[x][0];
}
void dfs2(int u, int p) {
  int x = q[u];
  dp2[u] = e[u] - w[u];
  for (auto v : a[u]) {
    if (v.first == p) continue;
    dfs2(v.first, u);
    dp2[u] += dp2[v.first];
    x += dp[v.first];
  }
  dp[u] = x - w[u];
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  t2[0] = 1;
  for (int i = 1; i < MAXN * 10; i++) t2[i] = (2 * t2[i - 1]) % MOD;
  int n;
  scanf("%d", &n);
  int x, y, z;
  for (int i = 0; i < n - 1; i++) {
    scanf("%d%d%d", &x, &y, &z);
    if (!z) {
      a[x].push_back({y, 0});
      a[y].push_back({x, 0});
    }
    if (z) {
      a[x].push_back({y, 1});
      a[y].push_back({x, 2});
    }
  }
  int m, v;
  dfs(1, 0);
  scanf("%d", &m);
  x = 1;
  while (m--) {
    scanf("%d", &y);
    v = lca(x, y);
    w[v]++;
    q[x]++;
    e[y]++;
    x = y;
  }
  dfs2(1, 0);
  long long ans = 0;
  for (int i = 2; i <= n; i++) {
    if (is[i] == 1) ans += t2[dp[i]] - 1;
    if (is[i] == 2) ans += t2[dp2[i]] - 1;
    ans %= MOD;
  }
  cout << ans;
}
