#include <bits/stdc++.h>
using namespace std;
const int maxn = 100000 + 10;
const int maxk = 1000000 + 10;
const int maxl = 18;
const int mod = 1e9 + 7;
int n, k;
vector<pair<int, int> > adj[maxn];
int par[maxn][maxl], s[maxk], dep[maxn], up[maxn], d[maxn];
int pw[maxk], ans;
void dfs(int v, int parent, int depth) {
  dep[v] = depth;
  par[v][0] = parent;
  for (int i = 1; i < maxl; i++) par[v][i] = par[par[v][i - 1]][i - 1];
  for (int i = 0; i < adj[v].size(); i++) {
    int u = adj[v][i].first;
    if (u != parent) dfs(u, v, depth + 1);
  }
  return;
}
int lca(int x, int y) {
  if (dep[x] > dep[y]) swap(x, y);
  int lg = 17;
  while (dep[y] > dep[x]) {
    if (dep[par[y][lg]] >= dep[x]) y = par[y][lg];
    lg--;
  }
  for (int i = 17; i >= 0; i--) {
    if (par[x][i] != par[y][i]) {
      x = par[x][i];
      y = par[y][i];
    }
  }
  if (x == y) return x;
  return par[x][0];
}
void Dfs(int v, int p, int dir) {
  int id = -1;
  for (int i = 0; i < adj[v].size(); i++) {
    int u = adj[v][i].first;
    int w = adj[v][i].second;
    if (u != p) {
      Dfs(u, v, w);
      up[v] += up[u];
      d[v] += d[u];
    } else
      id = i;
  }
  if (id != -1) {
    for (int i = id; i <= id; i++) {
      int u = adj[v][i].first;
      int w = adj[v][i].second;
      if (u == p) {
        if (w != 0) {
          if (dir == 2) {
            ans = (ans + pw[up[v] - 1]) % mod;
          } else {
            ans = (ans + pw[d[v] - 1]) % mod;
          }
        }
      }
    }
  }
}
int main() {
  pw[0] = 1;
  for (int i = 1; i < maxk; i++) pw[i] = (pw[i - 1] * 2) % mod;
  for (int i = 1; i < maxk; i++) pw[i] = (pw[i - 1] + pw[i]) % mod;
  scanf("%d", &n);
  for (int i = 1; i < n; i++) {
    int u, v, w;
    scanf("%d%d%d", &u, &v, &w);
    if (w == 1)
      adj[u].push_back(make_pair(v, 2));
    else
      adj[u].push_back(make_pair(v, w));
    adj[v].push_back(make_pair(u, w));
  }
  dfs(1, 0, 1);
  scanf("%d", &k);
  s[0] = 1;
  for (int i = 1; i <= k; i++) {
    scanf("%d", &s[i]);
    int anc = lca(s[i], s[i - 1]);
    up[s[i - 1]]++, up[anc]--;
    d[s[i]]++, d[anc]--;
  }
  Dfs(1, -1, -1);
  printf("%d\n", ans);
  return 0;
}
