#include <bits/stdc++.h>
using namespace std;
template <typename T>
void chmin(T &x, const T &y) {
  if (x > y) x = y;
}
template <typename T>
void chmax(T &x, const T &y) {
  if (x < y) x = y;
}
inline long long read() {
  long long x = 0, f = 1;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = x * 10 + ch - 48;
    ch = getchar();
  }
  return x * f;
}
const long long N = 1e5 + 10;
const long long mod = 1e9 + 7;
long long n, k, dep[N], f[N][40], dis1[N], dis2[N], ans, cnt, head[N];
struct node {
  long long to, from, next, dis;
} edge[N << 1];
inline void add(long long u, long long v, long long w) {
  edge[++cnt] = {v, u, head[u], w};
  head[u] = cnt;
}
inline long long qpow(long long x, long long y) {
  long long sum = 1;
  while (y) {
    if (y & 1) sum = x * sum % mod;
    y >>= 1;
    x = x * x % mod;
  }
  return sum;
}
inline void build(long long u, long long fa) {
  dep[u] = dep[fa] + 1;
  f[u][0] = fa;
  for (long long i = 0; f[u][i]; i++) f[u][i + 1] = f[f[u][i]][i];
  for (long long i = head[u]; i; i = edge[i].next) {
    long long v = edge[i].to;
    if (v == fa) continue;
    build(v, u);
  }
}
inline long long LCA(long long u, long long v) {
  if (dep[u] < dep[v]) swap(u, v);
  for (long long i = 30; i >= 0; i--)
    if (dep[u] - (1LL << i) >= dep[v]) u = f[u][i];
  if (u == v) return u;
  for (long long i = 30; i >= 0; i--)
    if (f[u][i] != f[v][i]) u = f[u][i], v = f[v][i];
  return f[u][0];
}
inline void dfs(long long u, long long fa) {
  for (long long i = head[u]; i; i = edge[i].next) {
    long long v = edge[i].to;
    if (v == fa) continue;
    dfs(v, u);
    dis1[u] += dis1[v];
    dis2[u] += dis2[v];
  }
}
signed main() {
  n = read();
  long long u, v, opt, lca;
  for (long long i = 1; i < n; i++) {
    u = read(), v = read(), opt = read();
    add(u, v, opt & 1);
    add(v, u, 0);
  }
  build(1, 0);
  k = read();
  v = 1;
  for (long long i = 1; i <= k; i++) {
    u = read();
    lca = LCA(u, v);
    dis1[v]++;
    dis2[u]++;
    dis1[lca]--, dis2[lca]--;
    v = u;
  }
  dfs(1, 0);
  for (long long i = 1; i <= cnt; i++) {
    if (!edge[i].dis) continue;
    v = edge[i].to, u = edge[i].from;
    if (dep[u] > dep[v])
      ans = (ans + qpow(2, dis2[u]) - 1 + mod) % mod;
    else
      ans = (ans + qpow(2, dis1[v]) - 1 + mod) % mod;
  }
  cout << ans % mod;
}
