#include <bits/stdc++.h>
inline int read() {
  static char ch;
  while (ch = getchar(), ch < '0' || ch > '9')
    ;
  int res = ch - 48;
  while (ch = getchar(), ch >= '0' && ch <= '9') res = res * 10 + ch - 48;
  return res;
}
const int N = 1e5 + 5, M = 17, mod = 1e9 + 7;
int n, m, last = 1, fa[N][M], dep[N], sum1[N], sum2[N], from[N];
int ecnt = 1, adj[N], nxt[N * 2], go[N * 2], ok[N * 2];
long long ans;
inline long long fpm(long long x, int Exp) {
  long long res = 1;
  for (; Exp > 0; Exp >>= 1, x = x * x % mod)
    if (Exp & 1) res = res * x % mod;
  return res;
}
inline void addEdge(const int &u, const int &v) {
  nxt[++ecnt] = adj[u];
  adj[u] = ecnt;
  go[ecnt] = v;
  nxt[++ecnt] = adj[v];
  adj[v] = ecnt;
  go[ecnt] = u;
}
inline int LCA(int u, int v) {
  if (dep[u] < dep[v]) std::swap(u, v);
  for (int d = dep[u] - dep[v], i = 0; d > 0; d >>= 1, ++i)
    if (d & 1) u = fa[u][i];
  if (u == v) return u;
  for (int i = (M - 1); i >= (0); --i)
    if (fa[u][i] != fa[v][i]) u = fa[u][i], v = fa[v][i];
  return fa[u][0];
}
inline int Jump(int u, int d) {
  for (int i = 0; d > 0; d >>= 1, ++i)
    if (d & 1) u = fa[u][i];
  return u;
}
inline void dfs(const int &u, const int &Fa) {
  fa[u][0] = Fa;
  dep[u] = dep[Fa] + 1;
  for (int i = (1); i < (M); ++i) fa[u][i] = fa[fa[u][i - 1]][i - 1];
  for (int e = adj[u]; e; e = nxt[e]) {
    int v = go[e];
    if (v == Fa) continue;
    from[v] = e;
    dfs(v, u);
  }
}
inline void calc(const int &u, const int &Fa) {
  for (int e = adj[u]; e; e = nxt[e]) {
    int v = go[e];
    if (v == Fa) continue;
    calc(v, u);
    sum1[u] += sum1[v];
    sum2[u] += sum2[v];
  }
  if (u == 1) return;
  if (!ok[from[u]]) {
    long long temp = fpm(2, sum2[u]) - 1;
    if (temp < 0) temp += mod;
    ans = (ans + temp) % mod;
  } else if (!ok[from[u] ^ 1]) {
    long long temp = fpm(2, sum1[u]) - 1;
    if (temp < 0) temp += mod;
    ans = (ans + temp) % mod;
  }
}
int main() {
  n = read();
  for (int i = (1); i < (n); ++i) {
    int u = read(), v = read(), w = read();
    addEdge(u, v);
    if (w == 0)
      ok[ecnt] = ok[ecnt - 1] = true;
    else
      ok[ecnt - 1] = true;
  }
  dfs(1, 0);
  m = read();
  for (int i = (1); i <= (m); ++i) {
    int u = last, v = read();
    int Lca = LCA(u, v);
    ++sum1[u];
    --sum1[Lca];
    --sum2[Lca];
    ++sum2[v];
    last = v;
  }
  calc(1, 0);
  std::cout << ans << std::endl;
  return 0;
}
