#include <bits/stdc++.h>
using namespace std;
const long long inf = 0x3f3f3f3f3f3f3f3f;
const long long mod = 1e9 + 7;
const int maxn = 100010;
const int maxn_log_v = 18;
struct Edge {
  int to, stu;
};
vector<Edge> g[maxn];
int root = 1;
int n, m;
int parent[maxn_log_v][maxn];
int depth[maxn];
void dfs(int v, int p, int d) {
  parent[0][v] = p;
  depth[v] = d;
  for (int i = 0; i < g[v].size(); ++i) {
    if (g[v][i].to != p) dfs(g[v][i].to, v, d + 1);
  }
}
void init(int V) {
  dfs(root, -1, 0);
  for (int k = 0; k + 1 < maxn_log_v; ++k) {
    for (int v = 1; v <= V; ++v) {
      if (parent[k][v] < 0)
        parent[k + 1][v] = -1;
      else
        parent[k + 1][v] = parent[k][parent[k][v]];
    }
  }
}
int lca(int u, int v) {
  if (depth[u] > depth[v]) swap(u, v);
  for (int k = 0; k < maxn_log_v; ++k) {
    if ((depth[v] - depth[u]) >> k & 1) {
      v = parent[k][v];
    }
  }
  if (u == v) return u;
  for (int k = maxn_log_v - 1; k >= 0; k--) {
    if (parent[k][u] != parent[k][v]) {
      u = parent[k][u];
      v = parent[k][v];
    }
  }
  return parent[0][u];
}
long long my_pow(long long x, int y) {
  long long ans = 1;
  while (y) {
    if (y & 1) ans = ans * x % mod;
    x = x * x % mod;
    y >>= 1;
  }
  return ans;
}
int dat1[maxn], dat2[maxn];
long long my_dfs(int v, int p) {
  long long ans = 0;
  for (int i = 0; i < g[v].size(); ++i) {
    if (g[v][i].to != p) {
      ans += my_dfs(g[v][i].to, v);
      dat1[v] += dat1[g[v][i].to];
      dat2[v] += dat2[g[v][i].to];
      if (g[v][i].stu == 1)
        ans = (ans + my_pow(2ll, dat1[g[v][i].to]) - 1) % mod;
      if (g[v][i].stu == -1)
        ans = (ans + my_pow(2ll, dat2[g[v][i].to]) - 1) % mod;
    }
  }
  return ans;
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i <= n; i++) g[i].clear();
  for (int i = 0; i < n - 1; i++) {
    int u, v, w;
    scanf("%d%d%d", &u, &v, &w);
    g[u].push_back((Edge){v, w});
    g[v].push_back((Edge){u, -w});
  }
  init(n);
  memset(dat1, 0, sizeof dat1);
  memset(dat2, 0, sizeof dat2);
  scanf("%d", &m);
  int cur = 1;
  for (int i = 0; i < m; ++i) {
    int nex;
    scanf("%d", &nex);
    int fa = lca(cur, nex);
    if (cur == fa) {
      dat2[nex]++;
      dat2[cur]--;
    } else if (nex == fa) {
      dat1[cur]++;
      dat1[nex]--;
    } else {
      dat1[cur]++;
      dat1[fa]--;
      dat2[nex]++;
      dat2[fa]--;
    }
    cur = nex;
  }
  printf("%I64d\n", (my_dfs(1, -1) + mod) % mod);
  return 0;
}
