#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
long long qpow(long long x, long long y) {
  long long re = 1, base = x % mod;
  while (y) {
    if (y & 1) re = (re * base) % mod;
    base = (base * base) % mod;
    y >>= 1;
  }
  return re;
}
struct node {
  int to, w;
  node(int to, int w) : to(to), w(w) {}
};
int n, k;
vector<node> e[100050];
int deep[100050], f[100050], anc[100050][25];
int up[100050], cnt[2][100050];
void init() {
  for (int i = 0; i <= n; i++) e[i].clear();
  memset(f, 0, sizeof(f)), memset(anc, 0, sizeof(anc)),
      memset(deep, 0, sizeof(deep));
  memset(up, 0, sizeof(up)), memset(cnt, 0, sizeof(cnt));
  deep[1] = 1;
}
void dfs1(int x, int fa) {
  anc[x][0] = f[x];
  for (int i = 1; i <= 20; i++) anc[x][i] = anc[anc[x][i - 1]][i - 1];
  for (int i = 0; i < e[x].size(); i++) {
    int next = e[x][i].to;
    if (next != fa) {
      f[next] = x;
      deep[next] = deep[x] + 1;
      up[next] = -e[x][i].w;
      dfs1(next, x);
    }
  }
}
int lca(int x, int y) {
  if (deep[x] < deep[y]) swap(x, y);
  for (int i = 20; i >= 0; i--)
    if (deep[anc[x][i]] >= deep[y]) x = anc[x][i];
  if (x == y) return x;
  for (int i = 20; i >= 0; i--)
    if (anc[x][i] != anc[y][i]) x = anc[x][i], y = anc[y][i];
  return f[x];
}
void dfs2(int x) {
  for (int i = 0; i < e[x].size(); i++) {
    int next = e[x][i].to;
    if (next == anc[x][0]) continue;
    dfs2(next);
    for (int j = 0; j < 2; j++) cnt[j][x] += cnt[j][next];
  }
}
int main() {
  scanf("%d", &n);
  init();
  for (int i = 1; i < n; i++) {
    int u, v, w;
    scanf("%d%d%d", &u, &v, &w);
    if (w == 0) {
      e[u].push_back(node(v, 0));
      e[v].push_back(node(u, 0));
    } else {
      e[u].push_back(node(v, 1));
      e[v].push_back(node(u, -1));
    }
  }
  dfs1(1, 0);
  scanf("%d", &k);
  int pre = 1, now;
  while (k--) {
    scanf("%d", &now);
    int x = lca(pre, now);
    cnt[0][pre]++;
    cnt[0][x]--;
    cnt[1][now]++;
    cnt[1][x]--;
    pre = now;
  }
  dfs2(1);
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    if (!up[i]) continue;
    if (up[i] == -1)
      ans = (ans + qpow(2, cnt[0][i]) - 1) % mod;
    else
      ans = (ans + qpow(2, cnt[1][i]) - 1) % mod;
  }
  ans = (ans + mod) % mod;
  printf("%d\n", ans);
  return 0;
}
