#include <bits/stdc++.h>
using namespace std;
int n, m, x[100005], y[100005], z[100005], fa[100005], top[100005], dep[100005],
    Bson[100005], sz[100005], Ans, a[100005], b[100005], bit[1000005];
int fst[100005], nxt[100005 << 1], to[100005 << 1], l;
void link(int x, int y) {
  to[++l] = y;
  nxt[l] = fst[x];
  fst[x] = l;
  to[++l] = x;
  nxt[l] = fst[y];
  fst[y] = l;
}
void dfs(int x) {
  sz[x] = 1;
  dep[x] = dep[fa[x]] + 1;
  for (int i = fst[x]; i; i = nxt[i])
    if (to[i] != fa[x]) {
      fa[to[i]] = x;
      dfs(to[i]);
      sz[x] += sz[to[i]];
      if (sz[to[i]] > sz[Bson[x]]) Bson[x] = to[i];
    }
}
void dfs(int x, int y) {
  top[x] = y;
  if (Bson[x]) dfs(Bson[x], y);
  for (int i = fst[x]; i; i = nxt[i])
    if (!top[to[i]]) dfs(to[i], to[i]);
}
int lca(int x, int y) {
  for (; top[x] != top[y]; x = fa[x])
    if (dep[top[x]] < dep[top[y]]) swap(x, y);
  return dep[x] < dep[y] ? x : y;
}
void Dfs(int x) {
  for (int i = fst[x]; i; i = nxt[i])
    if (to[i] != fa[x]) {
      Dfs(to[i]);
      a[x] += a[to[i]];
      b[x] += b[to[i]];
    }
}
int main() {
  bit[0] = 0;
  for (int i = 1; i <= 1000000; i++) bit[i] = (bit[i - 1] * 2 + 1) % 1000000007;
  scanf("%d", &n);
  for (int i = 1; i < n; i++) {
    scanf("%d%d%d", &x[i], &y[i], &z[i]);
    link(x[i], y[i]);
  }
  dfs(1);
  dfs(1, 1);
  scanf("%d", &m);
  for (int i = 1, x = 1, y; i <= m; i++) {
    scanf("%d", &y);
    int t = lca(x, y);
    a[x]++;
    b[y]++;
    a[t]--;
    b[t]--;
    x = y;
  }
  Dfs(1);
  for (int i = 1; i < n; i++)
    if (z[i]) {
      if (fa[x[i]] == y[i])
        Ans = (Ans + bit[b[x[i]]]) % 1000000007;
      else
        Ans = (Ans + bit[a[y[i]]]) % 1000000007;
    }
  printf("%d\n", Ans);
}
