#include <bits/stdc++.h>
using namespace std;
const int MODULO = 1000000007;
const int NMAX = 500005;
const int KMAX = 1000005;
int n, m, k, len, rmq[25][NMAX], fat[NMAX], niv[NMAX];
int eu[4 * NMAX], lg[4 * NMAX], start[NMAX];
int marsjos[NMAX], marssus[NMAX];
int sol;
vector<int> v[NMAX];
pair<int, int> b[NMAX];
inline void Dfs(int x, const int f, int nivel) {
  fat[x] = f;
  eu[++eu[0]] = x;
  start[x] = eu[0];
  niv[x] = nivel;
  for (vector<int>::iterator it = v[x].begin(); it != v[x].end(); it++)
    if ((*it) != f) {
      Dfs(*it, x, nivel + 1);
      eu[++eu[0]] = x;
    }
}
inline void RMQ() {
  int i, j;
  lg[2] = 1;
  for (i = 3; i < (NMAX << 2); i++) lg[i] = lg[i >> 1] + 1;
  for (i = 1; i <= eu[0]; i++) rmq[0][i] = eu[i];
  for (j = 1; j <= lg[eu[0]]; j++)
    for (i = 1; i <= (eu[0] - (1 << j) + 1); i++) {
      rmq[j][i] = rmq[j - 1][i];
      if (niv[rmq[j - 1][i + (1 << (j - 1))]] < niv[rmq[j - 1][i]])
        rmq[j][i] = rmq[j - 1][i + (1 << (j - 1))];
    }
}
inline int LCA(int x, int y) {
  int dif, aux;
  if (start[x] > start[y]) swap(x, y);
  dif = lg[start[y] - start[x] + 1];
  aux = rmq[dif][start[x]];
  if (niv[rmq[dif][start[y] - (1 << dif) + 1]] < niv[aux])
    aux = rmq[dif][start[y] - (1 << dif) + 1];
  return aux;
}
inline int Log(int x, int y) {
  int p = 1;
  while (y) {
    if (y & 1) p = (1LL * p * x) % MODULO;
    x = (1LL * x * x) % MODULO;
    y >>= 1;
  }
  return p;
}
inline void Dfs1(int x, const int f) {
  for (vector<int>::iterator it = v[x].begin(); it != v[x].end(); it++)
    if ((*it) != f) {
      Dfs1(*it, x);
      marssus[x] += marssus[*it];
      marsjos[x] += marsjos[*it];
    }
}
int main() {
  int i, j, x, y, z, lc, aux;
  cin.sync_with_stdio(false);
  cin >> n;
  for (i = 1; i < n; i++) {
    cin >> x >> y >> z;
    v[x].push_back(y);
    v[y].push_back(x);
    if (z == 1) {
      m++;
      b[m].first = y;
      b[m].second = x;
    }
  }
  Dfs(1, 0, 1);
  RMQ();
  cin >> k;
  y = 1;
  for (i = 1; i <= k; i++) {
    cin >> x;
    lc = LCA(x, y);
    if (y != lc) {
      marsjos[lc]--;
      marsjos[y]++;
    }
    if (x != lc) {
      marssus[lc]--;
      marssus[x]++;
    }
    y = x;
  }
  Dfs1(1, 0);
  for (i = 1; i <= m; i++) {
    if (niv[b[i].first] > niv[b[i].second])
      aux = marsjos[b[i].first];
    else
      aux = marssus[b[i].second];
    sol += Log(2, aux) - 1;
    if (sol >= MODULO) sol -= MODULO;
    if (sol < 0) sol += MODULO;
  }
  cout << sol << "\n";
  return 0;
}
