#include <bits/stdc++.h>
using namespace std;
const int maxn = 100010;
const int deg = 18;
const int mod = 1000000007;
struct edge {
  int v, next, val;
} e[maxn * 2];
int n, m, heads[maxn], fa[maxn][deg], dep[maxn], cnt;
int pre1[maxn], pre2[maxn];
long long vis[maxn];
long long sum1[maxn], sum2[maxn];
int dir[maxn];
void add(int u, int v, int val) {
  e[++cnt].next = heads[u];
  heads[u] = cnt;
  e[cnt].v = v;
  e[cnt].val = val;
}
void dfs(int u, int pree) {
  for (int i = heads[u]; i; i = e[i].next) {
    if (e[i].v != pree) {
      dep[e[i].v] = dep[u] + 1;
      fa[e[i].v][0] = u;
      dir[e[i].v] = e[i].val;
      dfs(e[i].v, u);
    }
  }
}
int LCA(int u, int v) {
  if (dep[u] > dep[v]) swap(u, v);
  for (int i = deg - 1; ~i; i--)
    if (dep[fa[v][i]] >= dep[u]) v = fa[v][i];
  if (u == v) return u;
  for (int i = deg - 1; ~i; i--)
    if (fa[u][i] != fa[v][i]) {
      u = fa[u][i];
      v = fa[v][i];
    }
  return fa[u][0];
}
void dfs1(int u, int pree) {
  sum1[u] = pre1[u];
  sum2[u] = pre2[u];
  for (int i = heads[u]; i; i = e[i].next) {
    if (e[i].v != pree) {
      dfs1(e[i].v, u);
      sum1[u] += sum1[e[i].v];
      sum2[u] += sum2[e[i].v];
    }
  }
  if (dir[u] == 1) vis[u] += sum1[u];
  if (dir[u] == -1) vis[u] += sum2[u];
}
long long qpow(long long x, long long y) {
  long long ans = 1;
  x %= mod;
  while (y) {
    if (y & 1) ans = (x * ans) % mod;
    x = (x * x) % mod;
    y >>= 1;
  }
  return ans;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i < n; i++) {
    int x, y, z;
    scanf("%d%d%d", &x, &y, &z);
    if (z == 0) {
      add(x, y, 0);
      add(y, x, 0);
    } else {
      add(x, y, 1);
      add(y, x, -1);
    }
  }
  dep[1] = fa[1][0] = 1;
  dfs(1, 0);
  for (int i = 1; i <= deg - 1; i++)
    for (int j = 1; j <= n; j++) fa[j][i] = fa[fa[j][i - 1]][i - 1];
  scanf("%d", &m);
  int last = 1, a;
  for (int i = 0; i < m; i++) {
    scanf("%d", &a);
    int lca = LCA(last, a);
    pre1[last]++;
    pre1[lca]--;
    pre2[a]++;
    pre2[lca]--;
    last = a;
  }
  dfs1(1, 0);
  long long ans = 0;
  for (int i = 2; i <= n; i++) {
    ans += qpow(2, vis[i]) - 1;
    if (ans >= mod) ans -= mod;
  }
  printf("%lld\n", ans);
  return 0;
}
