#include <bits/stdc++.h>
#pragma GCC optimize("O2")
using namespace std;
inline long long input() {
  long long n;
  cin >> n;
  return n;
}
long long poww(long long a, long long b, long long md) {
  return (!b ? 1
             : (b & 1 ? a * poww(a * a % md, b / 2, md) % md
                      : poww(a * a % md, b / 2, md) % md));
}
const int MAXN = 1e5 + 10;
const int MAXLG = 18;
const int MOD = 1e9 + 7;
const int MOD2 = 998244353;
const long long INF = 8e18;
struct edge {
  long long from;
  long long to;
  bool type;
};
vector<edge> edges;
bool mark[MAXN];
vector<pair<long long, long long> > adj[MAXN];
long long depth[MAXN];
long long par[MAXN][MAXLG];
long long upg[MAXN];
long long dog[MAXN];
long long ans;
long long n, k;
long long edq(long long val, long long u) {
  for (int i = 0; i < MAXLG; i++) {
    if (val & 1) u = par[u][i];
    val /= 2;
  }
  return u;
}
long long lca(long long v, long long u) {
  if (depth[v] > depth[u]) swap(v, u);
  u = edq(depth[u] - depth[v], u);
  if (v == u) return v;
  for (int i = MAXLG - 1; ~i; i--) {
    if (par[v][i] == par[u][i]) continue;
    v = par[v][i];
    u = par[u][i];
  }
  return par[v][0];
}
void solq(long long v, long long u) {
  long long x = lca(v, u);
  upg[v]++;
  dog[u]++;
  upg[x]--;
  dog[x]--;
}
void sfd(long long v) {
  mark[v] = true;
  for (auto h : adj[v]) {
    long long u = h.first;
    edge e = edges[h.second];
    if (mark[u]) continue;
    sfd(u);
    upg[v] += upg[u];
    dog[v] += dog[u];
    if (!e.type) continue;
    if (v == e.from) {
      ans += poww(2, upg[u], MOD);
      ans += MOD;
      ans--;
      ans %= MOD;
    } else {
      ans += poww(2, dog[u], MOD);
      ans += MOD;
      ans--;
      ans %= MOD;
    }
  }
}
void dfs(long long v) {
  mark[v] = true;
  for (auto h : adj[v]) {
    long long u = h.first;
    if (mark[u]) continue;
    depth[u] = depth[v] + 1;
    par[u][0] = v;
    for (int i = 1; i < MAXLG; i++) {
      par[u][i] = par[par[u][i - 1]][i - 1];
    }
    dfs(u);
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  cin >> n;
  edge e;
  edges.push_back(e);
  for (int i = 1; i < n; i++) {
    cin >> e.from >> e.to >> e.type;
    adj[e.from].push_back({e.to, i});
    adj[e.to].push_back({e.from, i});
    edges.push_back(e);
  }
  dfs(1);
  cin >> k;
  long long init = 1;
  long long tmp;
  while (k--) {
    cin >> tmp;
    solq(init, tmp);
    init = tmp;
  }
  memset(mark, 0, sizeof(mark));
  sfd(1);
  cout << ans << "\n";
}
