#include <bits/stdc++.h>
using namespace std;
const long long N = 1e5 + 10, LOG = 23, MAX = 1e6 + 10, M = 1e9 + 7;
long long n;
long long mark[N], level[N], par[N][LOG + 10], arr[MAX], cnt[N], tavan[MAX];
vector<long long> g[N];
map<pair<long long, long long>, long long> mp;
void DFS(long long v) {
  mark[v] = 1;
  for (long long u : g[v]) {
    if (!mark[u]) {
      level[u] = level[v] + 1;
      par[u][0] = v;
      DFS(u);
    }
  }
}
long long DFS2(long long v) {
  mark[v] = 2;
  for (long long u : g[v]) {
    if (mark[u] != 2) cnt[v] += DFS2(u);
  }
  return cnt[v];
}
long long getpar(long long v, long long dis) {
  long long cnt = 0;
  while (dis) {
    if (dis % 2) v = par[v][cnt];
    cnt++;
    dis /= 2;
  }
  return v;
}
long long MOD(long long a) { return (((a % M) + M) % M); }
void UPDATE() {
  for (long long i = 1; i <= LOG; i++) {
    for (long long node = 1; node <= n; node++)
      par[node][i] = par[par[node][i - 1]][i - 1];
  }
  tavan[0] = 1;
  for (long long i = 1; i < MAX; i++) {
    tavan[i] = MOD(tavan[i - 1] * 2);
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long u, v, x, q, ans = 0;
  cin >> n;
  for (long long i = 0; i < n - 1; i++) {
    cin >> u >> v >> x;
    mp[{u, v}] = x;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  DFS(1);
  UPDATE();
  cin >> q;
  arr[0] = 1;
  for (long long i = 1; i <= q; i++) {
    cin >> arr[i];
    long long lca;
    v = arr[i];
    u = arr[i - 1];
    cnt[u]++;
    cnt[v]++;
    if (level[v] < level[u]) swap(v, u);
    v = getpar(v, level[v] - level[u]);
    if (v == u)
      lca = v;
    else {
      for (long long j = LOG; j >= 0; j--) {
        if (par[v][j] != par[u][j]) {
          v = par[v][j];
          u = par[u][j];
        }
      }
      lca = par[v][0];
    }
    cnt[lca] -= 2;
  }
  DFS2(1);
  for (long long i = 1; i <= n; i++) {
    v = i;
    u = par[i][0];
    if ((mp.count({v, u}) && mp[{v, u}]) || (mp.count({u, v}) && mp[{u, v}])) {
      if (cnt[v] % 2 == 0)
        ans += tavan[cnt[v] / 2] - 1;
      else {
        if (mp.count({v, u}))
          ans += tavan[(cnt[v] + 1) / 2] - 1;
        else
          ans += tavan[cnt[v] / 2] - 1;
      }
      ans = MOD(ans);
    }
  }
  cout << ans;
  return 0;
}
