#include <bits/stdc++.h>
using namespace std;
const int maxN = 1e5 + 5;
const int LOG = 21;
const long long INF = 1e18;
const long long MOD = 1e9 + 7;
long long gcd(long long a, long long b) { return !b ? a : gcd(b, a % b); }
long long modP(long long a, long long b) {
  return (!b ? 1 : (modP(a, b / 2) * modP(a, b / 2) * (b % 2 ? a : 1)) % MOD);
}
bool flag;
long long pow2[10 * maxN], sum;
int n, k, i, u, v, t, l;
int st[maxN], fn[maxN];
int H[maxN], par[LOG][maxN];
vector<pair<int, int> > vec;
vector<int> G[maxN];
void DFSpar(int v, int p = 0, int h = 0) {
  par[0][v] = p;
  H[v] = h;
  for (i = 1; i < LOG; i++) {
    par[i][v] = par[i - 1][par[i - 1][v]];
  }
  for (auto u : G[v]) {
    if (u != p) {
      DFSpar(u, v, h + 1);
    }
  }
  return;
}
int getpar(int v, int h) {
  for (t = 0; t < LOG; t++) {
    if ((1 << t) & h) {
      v = par[t][v];
    }
  }
  return v;
}
int LCA(int v, int u) {
  if (H[v] < H[u]) {
    swap(v, u);
  }
  v = getpar(v, H[v] - H[u]);
  if (v == u) {
    return v;
  }
  for (t = LOG - 1; t > -1; t--) {
    if (par[t][v] != par[t][u]) {
      v = par[t][v];
      u = par[t][u];
    }
  }
  return par[0][v];
}
void DFS(int v, int p = 0) {
  for (auto u : G[v]) {
    if (u != p) {
      DFS(u, v);
      st[v] += st[u];
      fn[v] += fn[u];
    }
  }
  return;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  pow2[0] = 1;
  for (i = 1; i < 10 * maxN; i++) {
    pow2[i] = (pow2[i - 1] * 2) % MOD;
  }
  cin >> n;
  for (i = 0; i < n - 1; i++) {
    cin >> u >> v >> flag;
    if (flag) {
      vec.push_back({u, v});
    }
    G[u].push_back(v);
    G[v].push_back(u);
  }
  DFSpar(1);
  cin >> k;
  u = 1;
  for (i = 0; i < k; i++) {
    cin >> v;
    l = LCA(u, v);
    st[u] += 1;
    st[l] -= 1;
    fn[v] += 1;
    fn[l] -= 1;
    u = v;
  }
  DFS(1);
  for (auto e : vec) {
    u = e.first;
    v = e.second;
    if (H[u] < H[v]) {
      sum += pow2[st[v]] - 1;
    } else {
      sum += pow2[fn[u]] - 1;
    }
    sum %= MOD;
  }
  cout << sum << endl;
  return 0;
}
