#include <bits/stdc++.h>
using namespace std;
const int N = 100000, LOGN = 18, M = 1000000, mod = 1000000007;
int n, m, anc[N + 1][LOGN], up[N + 1][LOGN], down[N + 1][LOGN], dep[N + 1],
    dir[N + 1], expo[M + 1];
vector<pair<int, int> > v[N + 5];
void dfs(int dad, int node, int w) {
  dep[node] = dep[dad] + 1;
  dir[node] = w;
  anc[node][0] = dad;
  int sz = v[node].size();
  for (int i = 0; i < sz; i++) {
    if (v[node][i].first != dad) dfs(node, v[node][i].first, v[node][i].second);
  }
}
int main() {
  int x, y, w;
  scanf("%d", &n);
  for (int i = 1; i <= n - 1; i++) {
    scanf("%d %d %d", &x, &y, &w);
    v[x].push_back(make_pair(y, w));
    v[y].push_back(make_pair(x, -w));
  }
  dfs(0, 1, 0);
  for (int i = 1; i < LOGN; i++) {
    for (int j = 1; j <= n; j++) {
      anc[j][i] = anc[anc[j][i - 1]][i - 1];
    }
  }
  int cur = 1;
  scanf("%d", &m);
  while (m--) {
    scanf("%d", &x);
    int a = cur, b = x;
    bool dir = 0;
    if (dep[a] < dep[b]) {
      swap(a, b);
      dir = 1;
    }
    int diff = dep[a] - dep[b];
    for (int i = 0; i < LOGN; i++) {
      if (diff & (1 << i)) {
        if (dir)
          down[a][i]++;
        else
          up[a][i]++;
        a = anc[a][i];
      }
    }
    for (int i = LOGN - 1; i >= 0; i--) {
      if (anc[a][i] != anc[b][i]) {
        if (dir)
          down[a][i]++, up[b][i]++;
        else
          down[b][i]++, up[a][i]++;
        a = anc[a][i];
        b = anc[b][i];
      }
    }
    if (a != b) {
      if (dir)
        down[a][0]++, up[b][0]++;
      else
        down[b][0]++, up[a][0]++;
    }
    cur = x;
  }
  for (int i = LOGN - 1; i > 0; i--) {
    for (int j = 1; j <= n; j++) {
      down[j][i - 1] += down[j][i];
      down[anc[j][i - 1]][i - 1] += down[j][i];
      up[j][i - 1] += up[j][i];
      up[anc[j][i - 1]][i - 1] += up[j][i];
    }
  }
  long long ans = 0;
  expo[0] = 1;
  for (int i = 1; i <= M; i++) {
    expo[i] = expo[i - 1] * 2 % mod;
  }
  for (int i = 1; i <= n; i++) {
    if (dir[i] > 0)
      ans += expo[up[i][0]] - 1;
    else if (dir[i] < 0)
      ans += expo[down[i][0]] - 1;
  }
  printf("%d\n", ans % mod);
  return 0;
}
