#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
const int mod = 1e9 + 7;
long long quick(long long a, long long b) {
  long long ans = 1;
  while (b) {
    if (b & 1) ans = ans * a % mod;
    a = a * a % mod;
    b >>= 1;
  }
  return ans % mod;
}
int fa[N][20], dep[N], sum[N][2], ss[2002000];
pair<int, int> pp[N];
int flag[N], id[N];
vector<int> edge[N];
void dfs(int u, int fa) {
  for (int i = 0; i < edge[u].size(); i++) {
    int v = edge[u][i];
    if (v == fa) continue;
    dfs(v, u);
    sum[u][0] += sum[v][0];
    sum[u][1] += sum[v][1];
  }
}
queue<int> q;
int LCA(int x, int y) {
  if (dep[x] < dep[y]) swap(x, y);
  for (int i = 19; i >= 0; i--)
    if ((1 << i) & (dep[x] - dep[y])) x = fa[x][i];
  if (x == y) return x;
  for (int i = 19; i >= 0; i--)
    if (fa[x][i] != fa[y][i]) x = fa[x][i], y = fa[y][i];
  return fa[x][0];
}
int main() {
  int n;
  while (~scanf("%d", &n)) {
    for (int i = 0; i < n; i++) edge[i].clear();
    for (int i = 1; i < n; i++) {
      int a, b, c;
      scanf("%d%d%d", &a, &b, &c);
      pp[i] = make_pair(a, b);
      flag[i] = c;
      edge[a].push_back(b);
      edge[b].push_back(a);
    }
    memset(dep, -1, sizeof(dep));
    dep[1] = 0;
    fa[1][0] = 1;
    while (!q.empty()) q.pop();
    q.push(1);
    while (!q.empty()) {
      int u = q.front();
      q.pop();
      for (int i = 1; i < 20; i++) fa[u][i] = fa[fa[u][i - 1]][i - 1];
      for (int i = 0; i < edge[u].size(); i++) {
        int v = edge[u][i];
        if (dep[v] != -1) continue;
        dep[v] = dep[u] + 1;
        fa[v][0] = u;
        q.push(v);
      }
    }
    for (int i = 1; i < n; i++) {
      int a = pp[i].first;
      int b = pp[i].second;
      if (dep[a] > dep[b])
        id[a] = i;
      else
        id[b] = i;
      if (flag[i]) {
        if (dep[a] > dep[b])
          flag[i] = -1;
        else
          flag[i] = 1;
      }
    }
    int k;
    scanf("%d", &k);
    for (int i = 1; i <= k; i++) scanf("%d", &ss[i]);
    int cnt = 1;
    memset(sum, 0, sizeof(sum));
    for (int i = 1; i <= k; i++) {
      if (cnt == ss[i]) continue;
      int lca = LCA(cnt, ss[i]);
      sum[cnt][0]++;
      sum[lca][0]--;
      sum[ss[i]][1]++;
      sum[lca][1]--;
      cnt = ss[i];
    }
    dfs(1, 0);
    long long ans = 0;
    for (int i = 2; i <= n; i++) {
      if (flag[id[i]] == 0)
        continue;
      else if (flag[id[i]] == -1) {
        if (sum[i][1]) ans = (ans + quick(2, sum[i][1]) - 1) % mod;
      } else {
        if (sum[i][0]) ans = (ans + quick(2, sum[i][0]) - 1) % mod;
      }
    }
    printf("%I64d\n", (ans + mod) % mod);
  }
  return 0;
}
