#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
const int M = 1e6 + 10;
const int LOGN = 17;
int pows[M];
int ans;
vector<pair<int, int> > g[N];
int lev[N];
const int MOD = 1e9 + 7;
int par[LOGN][N], cntUps[LOGN][N], cntDowns[LOGN][N];
void dfsLCA(int v, int p) {
  par[0][v] = p;
  for (int h = 1; (1 << h) <= lev[v]; ++h)
    par[h][v] = par[h - 1][par[h - 1][v]];
  for (auto to : g[v])
    if (to.first != p) {
      lev[to.first] = lev[v] + 1;
      dfsLCA(to.first, v);
    }
}
int up(int v, int diff) {
  for (int i = 0; diff; i++, diff >>= 1)
    if (diff & 1) v = par[i][v];
  return v;
}
int lca(int x, int y) {
  if (lev[x] > lev[y]) swap(x, y);
  y = up(y, lev[y] - lev[x]);
  if (x == y) return x;
  for (int i = LOGN - 1; i >= 0; --i)
    if (par[i][x] != par[i][y]) {
      x = par[i][x];
      y = par[i][y];
    }
  return par[0][x];
}
int n;
void updateAll(int cnt[LOGN][N]) {
  for (int i = LOGN - 1; i >= 1; --i) {
    int h = 1 << i;
    for (int v = 0; v < n; ++v)
      if (lev[v] >= h) {
        cnt[i - 1][v] += cnt[i][v];
        cnt[i - 1][par[i - 1][v]] += cnt[i][v];
      }
  }
}
void addPath(int from, int to, int cnt[LOGN][N]) {
  for (int i = LOGN - 1; i >= 0; --i)
    if (lev[par[i][from]] > lev[to]) {
      cnt[i][from]++;
      from = par[i][from];
    }
  cnt[0][from]++;
}
void dfs(int v, int p) {
  for (auto to : g[v])
    if (to.first != p) {
      dfs(to.first, v);
      if (to.second == 1)
        ans = (ans + pows[cntUps[0][to.first]]) % MOD;
      else if (to.second == 2)
        ans = (ans + pows[cntDowns[0][to.first]]) % MOD;
    }
}
int main() {
  int pw = 1;
  for (int i = 1; i < M; ++i) {
    pows[i] = (pows[i - 1] + pw) % MOD;
    pw = (pw * 2) % MOD;
  }
  cin >> n;
  for (int i = 0; i < n - 1; ++i) {
    int x, y, z;
    scanf("%d%d%d", &x, &y, &z);
    --x;
    --y;
    if (z == 0) {
      g[x].push_back(make_pair(y, 0));
      g[y].push_back(make_pair(x, 0));
    } else if (z == 1) {
      g[x].push_back(make_pair(y, 1));
      g[y].push_back(make_pair(x, 2));
    }
  }
  int m;
  cin >> m;
  vector<int> a(m + 1);
  a[0] = 0;
  for (int i = 0; i < m; ++i) {
    scanf("%d", &a[i + 1]);
    --a[i + 1];
  }
  dfsLCA(0, 0);
  for (int i = 0; i + 1 < a.size(); ++i) {
    int lc = lca(a[i], a[i + 1]);
    if (lc != a[i]) addPath(a[i], lc, cntUps);
    if (lc != a[i + 1]) addPath(a[i + 1], lc, cntDowns);
  }
  updateAll(cntUps);
  updateAll(cntDowns);
  dfs(0, 0);
  cout << ans;
  return 0;
}
