#include <bits/stdc++.h>
using namespace std;
const int N = 100000;
const int LNN = 17;
const int MODNUM = 1000000000 + 7;
int depth[N], pa[LNN][N], pa_idx[N];
vector<int> adj[N], cost[N], other[N];
int up[N], down[N];
int upSum[N], downSum[N];
void dfs(int cur, int prev, int cur_idx, int _depth = 0) {
  if (cur_idx != -1) {
    pa_idx[cur] = other[prev][cur_idx];
  } else {
    pa_idx[cur] = -1;
  }
  pa[0][cur] = prev;
  depth[cur] = _depth;
  for (int i = 0; i < adj[cur].size(); i++) {
    if (adj[cur][i] != prev) {
      dfs(adj[cur][i], cur, i, _depth + 1);
    }
  }
}
int LCA(int u, int v) {
  if (depth[u] < depth[v]) swap(u, v);
  int diff = depth[u] - depth[v];
  for (int i = 0; i < LNN; i++)
    if ((diff >> i) & 1) u = pa[i][u];
  if (u == v) return u;
  for (int i = LNN - 1; i >= 0; i--)
    if (pa[i][u] != pa[i][v]) {
      u = pa[i][u];
      v = pa[i][v];
    }
  return pa[0][u];
}
void dfs2(int cur, int prev) {
  upSum[cur] = up[cur];
  downSum[cur] = down[cur];
  for (int i = 0; i < adj[cur].size(); i++) {
    if (adj[cur][i] != prev) {
      dfs2(adj[cur][i], cur);
      upSum[cur] = (upSum[cur] + upSum[adj[cur][i]]) % (MODNUM - 1);
      downSum[cur] = (downSum[cur] + downSum[adj[cur][i]]) % (MODNUM - 1);
    }
  }
}
long long exp(long long x, int n) {
  if (n == 0) return 1;
  long long num = exp(x, n / 2);
  if (n % 2) return (((num * num) % MODNUM) * x) % MODNUM;
  return (num * num) % MODNUM;
}
int main(int argc, char const *argv[]) {
  int n;
  scanf("%d\n", &n);
  for (int i = 0; i < n - 1; ++i) {
    int a, b, c;
    scanf("%d %d %d\n", &a, &b, &c);
    a--;
    b--;
    adj[a].push_back(b);
    adj[b].push_back(a);
    cost[a].push_back(0);
    cost[b].push_back(c);
    other[a].push_back(adj[b].size() - 1);
    other[b].push_back(adj[a].size() - 1);
  }
  for (int i = 0; i < n; ++i) {
    up[i] = down[i] = 0;
  }
  dfs(0, -1, -1);
  for (int i = 1; i < LNN; i++)
    for (int j = 0; j < n; j++)
      if (pa[i - 1][j] != -1) pa[i][j] = pa[i - 1][pa[i - 1][j]];
  int k;
  scanf("%d\n", &k);
  int cur = 0;
  for (int i = 0; i < k; i++) {
    int next;
    scanf("%d ", &next);
    next--;
    int lca = LCA(cur, next);
    up[cur] += 1;
    down[next] += 1;
    up[lca] -= 1;
    down[lca] -= 1;
    cur = next;
  }
  dfs2(0, -1);
  int ans = 0;
  for (int i = 1; i < n; i++) {
    if (cost[i][pa_idx[i]]) {
      ans = (ans + ((exp(2, upSum[i]) - 1 + MODNUM) % MODNUM)) % MODNUM;
    } else if (cost[pa[0][i]][other[i][pa_idx[i]]]) {
      ans = (ans + ((exp(2, downSum[i]) - 1 + MODNUM) % MODNUM)) % MODNUM;
    }
  }
  printf("%d\n", ans);
  return 0;
}
