#include <bits/stdc++.h>
int MOD = int(1e9) + 7;
inline int add(int a, int b) {
  return (a + b >= MOD) ? (a + b - MOD) : (a + b);
}
inline void inc(int &a, int b) { a = add(a, b); }
inline int sub(int a, int b) { return (a - b < 0) ? (a - b + MOD) : (a - b); }
inline void dec(int &a, int b) { a = sub(a, b); }
inline int mul(int a, int b) { return (a * 1ll * b) % MOD; }
using namespace std;
const int N = 100000, LOG = 20;
vector<int> ladj[N + 1];
int P[N], H[N], dp[N][LOG], up[N], down[N], to[2 * N], counter[2 * N];
bool valid[2 * N];
void dfs(int u, int p, int lvl) {
  P[u] = p;
  H[u] = lvl;
  for (int edge : ladj[u]) {
    int v = to[edge];
    if (v != p) dfs(v, u, lvl + 1);
  }
}
void init(int n) {
  for (int i = 0; i < n; i++) dp[i][0] = P[i];
  for (int j = 1; j < LOG; j++)
    for (int i = 0; i < n; i++) dp[i][j] = dp[dp[i][j - 1]][j - 1];
}
int lca(int u, int v) {
  if (H[u] < H[v]) swap(u, v);
  for (int i = LOG - 1; i >= 0; i--)
    if (H[dp[u][i]] >= H[v]) u = dp[u][i];
  if (u == v) return u;
  for (int i = LOG - 1; i >= 0; i--)
    if (dp[u][i] != dp[v][i]) u = dp[u][i], v = dp[v][i];
  return P[u];
}
pair<int, int> dfs2(int u) {
  int a = up[u], b = 0, aux = -1;
  for (int edge : ladj[u]) {
    int v = to[edge];
    if (v == P[u])
      aux = edge;
    else {
      pair<int, int> temp = dfs2(v);
      a += temp.first, b += temp.second;
      counter[edge] = -temp.second;
    }
  }
  if (aux != -1) {
    counter[aux] = a;
  }
  b += down[u];
  return {a, b};
}
int pow(int x) {
  if (!x) return 1;
  int p = pow(x / 2);
  p = mul(p, p);
  if (x % 2) p = mul(p, 2);
  return p;
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n - 1; i++) {
    int u, v, t;
    scanf("%d %d %d", &u, &v, &t);
    u--, v--;
    to[2 * i + 1] = u;
    to[2 * i] = v;
    ladj[u].push_back(2 * i);
    ladj[v].push_back(2 * i + 1);
    valid[2 * i] = true;
    valid[2 * i + 1] = !t;
  }
  dfs(0, 0, 0);
  init(n);
  int k, u = 0;
  scanf("%d", &k);
  while (k--) {
    int v;
    scanf("%d", &v);
    v--;
    int p = lca(u, v);
    up[u]++, up[p]--, down[p]++, down[v]--;
    u = v;
  }
  dfs2(0);
  int ans = 0;
  for (int i = 0; i < 2 * n - 2; i++) {
    if (!valid[i]) inc(ans, sub(pow(counter[i]), 1));
  }
  printf("%d\n", ans);
  return 0;
}
