#include <bits/stdc++.h>
using namespace std;
int to[200001 * 2], nex[200001 * 2], fir[200001], up[200001], dn[200001],
    dep[200001], sz[200001], fa[200001], top[200001];
int E, n, m, x;
struct edg {
  int s, t, bo;
} e[200001];
int mi(int x, int y) {
  int ret = 1;
  for (; y; y >>= 1, x = 1ll * x * x % 1000000007)
    if (y & 1) ret = 1ll * ret * x % 1000000007;
  return ret;
}
void add(int x, int y) {
  to[++E] = y;
  nex[E] = fir[x];
  fir[x] = E;
}
int build(int now, int fat) {
  sz[now] = 1;
  fa[now] = fat;
  dep[now] = dep[fat] + 1;
  for (int i = fir[now]; i; i = nex[i])
    if (to[i] != fat) sz[now] += build(to[i], now);
  return sz[now];
}
void dfs(int now, int tp) {
  top[now] = tp;
  int bes = 0;
  for (int i = fir[now]; i; i = nex[i])
    if (to[i] != fa[now] && sz[to[i]] > sz[bes]) bes = to[i];
  if (bes) dfs(bes, tp);
  for (int i = fir[now]; i; i = nex[i])
    if (to[i] != fa[now] && to[i] != bes) dfs(to[i], to[i]);
}
int lca(int x, int y) {
  while (top[x] != top[y]) {
    if (dep[top[x]] > dep[top[y]]) swap(x, y);
    y = fa[top[y]];
  }
  return dep[x] < dep[y] ? x : y;
}
void calc(int now) {
  for (int i = fir[now]; i; i = nex[i])
    if (to[i] != fa[now]) {
      calc(to[i]);
      up[now] += up[to[i]];
      dn[now] += dn[to[i]];
    }
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i < n; i++) {
    scanf("%d%d%d", &e[i].s, &e[i].t, &e[i].bo);
    add(e[i].s, e[i].t);
    add(e[i].t, e[i].s);
  }
  build(1, 0);
  dfs(1, 1);
  scanf("%d", &m);
  int las = 1;
  for (int i = 1; i <= m; i++) {
    scanf("%d", &x);
    int lc = lca(x, las);
    up[las]++;
    up[lc]--;
    dn[x]++;
    dn[lc]--;
    las = x;
  }
  calc(1);
  int ret = 0;
  for (int i = 1; i < n; i++)
    if (e[i].bo)
      if (e[i].s == fa[e[i].t])
        (ret += mi(2, up[e[i].t]) - 1) %= 1000000007;
      else
        (ret += mi(2, dn[e[i].s]) - 1) %= 1000000007;
  printf("%d\n", ret);
  return 0;
}
