#include <bits/stdc++.h>
#pragma GCC optimize("-Ofast", "-funroll-all-loops")
using namespace std;
const long long N = 1e5 + 10, M = N * 2, mod = 1e9 + 7;
long long n, m, s[N * 10], sz[N], bl[N], pos[N], dep[N], f[N], son[N], cnt,
    p1[N], p2[N], mi[N * 10] = {1}, res;
long long head[N], nex[M], to[M], w[M], tot;
inline void add(long long a, long long b, long long c) {
  to[++tot] = b;
  nex[tot] = head[a];
  w[tot] = c;
  head[a] = tot;
}
void dfs1(long long x) {
  sz[x] = 1;
  for (long long i = head[x]; i; i = nex[i])
    if (to[i] != f[x]) {
      f[to[i]] = x;
      dep[to[i]] = dep[x] + 1;
      dfs1(to[i]);
      sz[x] += sz[to[i]];
      if (sz[to[i]] > sz[son[x]]) son[x] = to[i];
    }
}
void dfs2(long long x, long long belong) {
  pos[x] = ++cnt;
  bl[x] = belong;
  if (son[x]) dfs2(son[x], belong);
  for (long long i = head[x]; i; i = nex[i])
    if (dep[to[i]] > dep[x] && to[i] != son[x]) dfs2(to[i], to[i]);
}
inline long long lca(long long x, long long y) {
  while (bl[x] != bl[y]) {
    if (dep[bl[x]] < dep[bl[y]]) swap(x, y);
    x = f[bl[x]];
  }
  return dep[x] > dep[y] ? y : x;
}
void dfs(long long x, long long fa) {
  for (long long i = head[x]; i; i = nex[i])
    if (to[i] != fa) {
      dfs(to[i], x);
      p1[x] += p1[to[i]], p2[x] += p2[to[i]];
      if (w[i] == 1)
        res = (res + mi[p1[to[i]]] - 1 + mod) % mod;
      else if (w[i] == -1)
        res = (res + mi[p2[to[i]]] - 1 + mod) % mod;
    }
}
signed main() {
  cin >> n;
  for (long long i = 1, a, b, c; i < n; i++)
    scanf("%lld %lld %lld", &a, &b, &c), add(a, b, c), add(b, a, -c);
  cin >> m;
  s[0] = 1;
  for (long long i = 1; i <= m; i++)
    scanf("%lld", &s[i]), mi[i] = mi[i - 1] * 2 % mod;
  dfs1(1);
  dfs2(1, 1);
  for (long long i = 1, l; i <= m; i++) {
    l = lca(s[i], s[i - 1]);
    p1[s[i - 1]]++, p1[l]--, p2[s[i]]++, p2[l]--;
  }
  dfs(1, 1);
  cout << res;
  return 0;
}
