#include <bits/stdc++.h>
namespace TNT {
const int MAXN = 1e5 + 10;
const int mod = 1e9 + 7;
inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = (x << 3) + (x << 1) + (ch ^ 48);
    ch = getchar();
  }
  return x * f;
}
inline void write(int x) {
  if (x < 0) putchar('-'), x = -x;
  if (x > 9) write(x / 10);
  putchar(x % 10 + '0');
}
int qpow(int x, int y) {
  int ans = 1;
  while (y) {
    if (y & 1) ans = (long long)ans * x % mod;
    x = (long long)x * x % mod;
    y >>= 1;
  }
  return ans;
}
struct edge {
  int nex;
  int v;
  bool w;
} e[MAXN << 1];
int head[MAXN], tot;
inline void add(int x, int y, bool z) {
  e[++tot] = (edge){head[x], y, z}, head[x] = tot;
}
int f[MAXN], dep[MAXN], heavy[MAXN], size[MAXN];
void dfs1(int u, int fa) {
  f[u] = fa;
  dep[u] = dep[fa] + 1;
  size[u] = 1;
  for (int i = head[u], v; i; i = e[i].nex) {
    v = e[i].v;
    if (v == fa) continue;
    dfs1(v, u);
    size[u] += size[v];
    if (size[v] > size[heavy[u]]) heavy[u] = v;
  }
}
int top[MAXN];
void dfs2(int u, int tp) {
  top[u] = tp;
  if (!heavy[u]) return;
  dfs2(heavy[u], tp);
  for (int i = head[u], v; i; i = e[i].nex) {
    v = e[i].v;
    if (v == f[u] || v == heavy[u]) continue;
    dfs2(v, v);
  }
}
inline int LCA(int x, int y) {
  while (top[x] != top[y]) {
    if (dep[top[x]] < dep[top[y]]) std::swap(x, y);
    x = f[top[x]];
  }
  return dep[x] <= dep[y] ? x : y;
}
int dis1[MAXN], dis2[MAXN], ans;
void dfs(int u, int fa) {
  for (int i = head[u], v; i; i = e[i].nex) {
    v = e[i].v;
    if (v == fa) continue;
    dfs(v, u);
    dis1[u] += dis1[v];
    dis2[u] += dis2[v];
  }
  for (int i = head[u], v; i; i = e[i].nex) {
    v = e[i].v;
    if (e[i].w) {
      if (v == fa)
        ans = ((long long)ans + qpow(2, dis1[u]) - 1 + mod) % mod;
      else
        ans = ((long long)ans + qpow(2, dis2[v]) - 1 + mod) % mod;
    }
  }
}
inline void main() {
  int n = read(), x, y, z;
  for (int i = 1; i < n; i++) {
    x = read(), y = read(), z = read();
    add(x, y, 0), add(y, x, z);
  }
  dfs1(1, 0), dfs2(1, 1);
  z = read(), x = 1;
  for (int i = 1, lca; i <= z; i++) {
    y = read();
    lca = LCA(x, y);
    ++dis1[x], --dis1[lca];
    ++dis2[y], --dis2[lca];
    x = y;
  }
  dfs(1, 0);
  write(ans);
  return;
}
}  // namespace TNT
int main() {
  TNT::main();
  return 0;
}
