#include <bits/stdc++.h>
template <typename T>
inline T &read(T &x) {
  x = 0;
  bool f = false;
  short ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') f = true;
    ch = getchar();
  }
  while (isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ '0'), ch = getchar();
  if (f) x = -x;
  return x;
}
constexpr int N = 1e5 + 5, mod = 1e9 + 7;
int n, K, ans, dif1[N], dif2[N];
int e_cnt = 1, heads[N];
int siz[N], dep[N], fa[N], dfn[N], cnt, son[N], top[N];
struct Edge {
  int v, nxt;
  bool directed;
} e[N << 1];
inline void add(int u, int v, bool typ) {
  if (typ) {
    e[++e_cnt].v = v, e[e_cnt].nxt = heads[u], heads[u] = e_cnt;
    e[++e_cnt].v = u, e[e_cnt].nxt = heads[v], heads[v] = e_cnt;
    e[e_cnt].directed = true;
  } else {
    e[++e_cnt].v = v, e[e_cnt].nxt = heads[u], heads[u] = e_cnt;
    e[++e_cnt].v = u, e[e_cnt].nxt = heads[v], heads[v] = e_cnt;
  }
}
void dfs1(int x) {
  siz[x] = 1;
  for (int i = heads[x], v; i; i = e[i].nxt) {
    if ((v = e[i].v) != fa[x]) {
      dep[v] = dep[x] + 1;
      fa[v] = x;
      dfs1(v);
      siz[x] += siz[v];
      if (siz[v] > siz[son[x]]) son[x] = v;
    }
  }
}
void dfs2(int x, int topp) {
  dfn[x] = ++cnt;
  top[x] = topp;
  if (son[x]) {
    dfs2(son[x], topp);
  }
  for (int i = heads[x], v; i; i = e[i].nxt) {
    if ((v = e[i].v) != fa[x] && v != son[x]) {
      dfs2(v, v);
    }
  }
}
inline int getlca(int u, int v) {
  while (top[u] != top[v])
    dep[top[u]] > dep[top[v]] ? u = fa[top[u]] : v = fa[top[v]];
  return dep[u] > dep[v] ? v : u;
}
inline int qpow(long long base, int exp) {
  long long res = 1;
  while (exp) {
    if (exp & 1) res = res * base % mod;
    exp >>= 1;
    base = base * base % mod;
  }
  return res;
}
void solve(int x) {
  for (int i = heads[x], v; i; i = e[i].nxt) {
    if ((v = e[i].v) != fa[x]) {
      solve(v);
      dif1[x] += dif1[v];
      dif2[x] += dif2[v];
      if (e[i].directed) {
        ans += qpow(2, dif2[v]) - 1;
        if (ans >= mod) ans -= mod;
        if (ans < 0) ans += mod;
      }
      if (e[i ^ 1].directed) {
        ans += qpow(2, dif1[v]) - 1;
        if (ans >= mod) ans -= mod;
        if (ans < 0) ans += mod;
      }
    }
  }
}
int main() {
  read(n);
  for (int i = 1, a, b, c; i < n; ++i) {
    read(a), read(b), read(c);
    add(a, b, c);
  }
  fa[1] = 1, dfs1(1), dfs2(1, 1);
  read(K);
  int lass = 1;
  for (int i = 1, s, lca; i <= K; ++i) {
    read(s);
    lca = getlca(lass, s);
    ++dif1[lass], --dif1[lca];
    ++dif2[s], --dif2[lca];
    lass = s;
  }
  solve(1);
  printf("%d", ans);
  return 0;
}
