#include <bits/stdc++.h>
using namespace std;
vector<pair<int, bool> > G[100010];
int root;
int parent[20][100010];
int depth[100010];
int in[100010], out[100010], mp[100010 << 1];
int dfs_clock = 0;
bool a[100010], b[100010];
int POW[100010 * 10];
void dfs(int v, int p, int d) {
  in[v] = ++dfs_clock;
  mp[dfs_clock - 1] = v;
  parent[0][v] = p;
  depth[v] = d;
  for (int i = 0, sz = G[v].size(); i < sz; i++) {
    int u = G[v][i].first;
    bool flag = G[v][i].second;
    if (u == p) {
      b[v] = flag;
    } else {
      dfs(u, v, d + 1);
      a[u] = flag;
    }
  }
  out[v] = ++dfs_clock;
  mp[dfs_clock - 1] = v;
}
void init(int V) {
  dfs_clock = 0;
  dfs(root, -1, 0);
  for (int k = 0; k + 1 < 20; 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]];
  }
  POW[0] = 1;
  for (int i = 1; i <= 1000000; i++) POW[i] = (POW[i - 1] << 1) % 1000000007;
}
int lca(int u, int v) {
  if (depth[u] > depth[v]) swap(u, v);
  for (int k = 0; k < 20; k++)
    if ((depth[v] - depth[u]) >> k & 1) v = parent[k][v];
  if (v == u) return u;
  for (int k = 19; k >= 0; k--)
    if (parent[k][u] != parent[k][v]) {
      u = parent[k][u];
      v = parent[k][v];
    }
  return parent[0][u];
}
void update(int k, int det, int *a, int n) {
  for (int i = k; i <= n; i += (i & (-i))) a[i] += det;
}
int getSum(int k, int *a) {
  int res = 0;
  for (int i = k; i > 0; i -= (i & (-i))) res += a[i];
  return res;
}
int c1[100010 << 1], c2[100010 << 1];
int s[100010 * 10];
int main() {
  int n, k;
  scanf("%d", &n);
  for (int i = 1; i < n; i++) {
    int u, v, typ;
    scanf("%d%d%d", &u, &v, &typ);
    if (typ == 0) {
      G[u].push_back(make_pair(v, true));
      G[v].push_back(make_pair(u, true));
    } else {
      G[u].push_back(make_pair(v, true));
      G[v].push_back(make_pair(u, false));
    }
  }
  root = 1;
  fill(a, a + n + 10, 1);
  fill(b, b + n + 10, 1);
  init(n);
  memset(c1, 0, sizeof(c1));
  memset(c2, 0, sizeof(c2));
  scanf("%d", &k);
  for (int i = 0; i < k; i++) scanf("%d", &s[i]);
  int tmp = 1;
  for (int i = 0; i < k; i++) {
    int p = lca(tmp, s[i]);
    update(in[p] + 1, 1, c2, dfs_clock);
    update(in[tmp] + 1, -1, c2, dfs_clock);
    tmp = s[i];
    update(in[p] + 1, 1, c1, dfs_clock);
    update(in[tmp] + 1, -1, c1, dfs_clock);
    int t1 = getSum(in[i], c2);
  }
  int ans = 0;
  for (int i = 2; i <= n; i++) {
    if (!a[i]) {
      int num1 = getSum(in[i], c1) - getSum(out[i], c1);
      ans = (ans + POW[num1] - 1) % 1000000007;
    }
    if (!b[i]) {
      int t1 = getSum(in[i], c2);
      int t2 = getSum(out[i], c2);
      int num2 = getSum(in[i], c2) - getSum(out[i], c2);
      ans = (ans + POW[num2] - 1) % 1000000007;
    }
  }
  printf("%d\n", ans);
}
