#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-8;
inline int max(int a, int b) { return a < b ? b : a; }
inline int min(int a, int b) { return a > b ? b : a; }
inline long long max(long long a, long long b) { return a < b ? b : a; }
inline long long min(long long a, long long b) { return a > b ? b : a; }
const int mod = 1e9 + 7;
const int N = 1e6 + 500;
const long long inf = 1e18;
long long fl(long long x, long long y) {
  if (x >= 0) return x / y;
  return x / y - (x % y ? 1 : 0);
}
long long cl(long long x, long long y) {
  if (x >= 0) return (x + y - 1) / y;
  return x / y;
}
long long power(long long a, long long n) {
  if (n == 0) {
    return 1;
  }
  long long b = power(a, n / 2);
  b = b * b % mod;
  if (n % 2) b = b * a % mod;
  return b;
}
vector<pair<int, int> > G[N];
int tin[N], tout[N], timer, depth[N], up[N], down[N], M[N][30], LOG[N];
vector<int> B;
int A[N];
int LCA(int u, int v) {
  if (depth[u] > depth[v]) swap(u, v);
  int dif = depth[v] - depth[u], c = 0;
  while (dif > 0) {
    if (dif & 1) {
      v = M[v][c];
    }
    dif /= 2;
    c++;
  }
  if (u == v) return u;
  for (int i = 17; i >= 0; i--) {
    if (M[u][i] == M[v][i]) continue;
    u = M[u][i];
    v = M[v][i];
  }
  return M[u][0];
}
void dfs(int i, int par, int d) {
  tin[i] = timer++;
  depth[i] = d;
  M[i][0] = par;
  B.push_back(i);
  for (int j = 0; j < G[i].size(); ++j) {
    if (G[i][j].first == par) continue;
    dfs(G[i][j].first, i, d + 1);
    B.push_back(i);
  }
  tout[i] = timer++;
}
int ancestor(int A, int b) { return (tin[A] <= tin[b] && tout[A] >= tout[b]); }
void dfs2(int i, int par) {
  for (int j = 0; j < G[i].size(); ++j) {
    if (G[i][j].first == par) continue;
    dfs2(G[i][j].first, i);
    down[i] += down[G[i][j].first];
    up[i] += up[G[i][j].first];
  }
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n - 1; ++i) {
    int u, v, x;
    scanf("%d %d %d", &u, &v, &x);
    G[v].push_back(make_pair(u, x));
    if (x == 0)
      G[u].push_back(make_pair(v, x));
    else
      G[u].push_back(make_pair(v, x ^ 1));
  }
  int k;
  scanf("%d", &k);
  for (int i = 0; i < k; ++i) {
    scanf("%d", &A[i]);
  }
  dfs(1, 0, 0);
  LOG[1] = 0;
  int c1 = 1;
  for (int i = 2; i < N; ++i) {
    if (c1 * 2 == i) {
      LOG[i]++;
      c1 *= 2;
    }
    LOG[i] += LOG[i - 1];
  }
  for (int i = 1; i < n + 1; ++i) {
    for (int j = 1; j < 18; ++j) {
      M[i][j] = M[M[i][j - 1]][j - 1];
    }
  }
  int prev = 1;
  for (int i = 0; i < k; ++i) {
    int p = LCA(prev, A[i]);
    up[prev]++;
    up[p]--;
    down[A[i]]++;
    down[p]--;
    prev = A[i];
  }
  dfs2(1, 0);
  long long ans = 0;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < G[i].size(); ++j) {
      if (G[i][j].second == 0) continue;
      if (ancestor(i, G[i][j].first)) {
        int x = down[G[i][j].first];
        ans = (ans + (power(2, x) - 1)) % mod;
      } else {
        int x = up[i];
        ans = (ans + (power(2, x) - 1)) % mod;
      }
    }
  }
  printf("%lld\n", (ans + mod) % mod);
  return 0;
}
