#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
  long long r;
  while (b != 0) {
    r = a % b;
    a = b;
    b = r;
  }
  return a;
}
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
const int maxn = 100010;
const int mod = 1000000007;
int n;
vector<pair<int, int> > adj[maxn];
int price[maxn];
int sum[2][maxn];
int ntra[2][maxn];
const int maxe = 20;
int nchain, nbase;
int hchain[maxn];
int ichain[maxn];
int size[maxn];
int pib[maxn];
int vis[maxn];
int lev[maxn];
int p[maxe][maxn];
int tin[maxn];
int tou[maxn];
int tms;
long long ex(long long n, long long k) {
  if (k == 0) return 1;
  if (k % 2 == 1) return n * ex(n, k - 1) % mod;
  long long t = ex(n, k >> 1);
  return t * t % mod;
}
void init() {
  memset(vis, 0, sizeof(vis));
  memset(p, 0, sizeof(p));
  memset(lev, 0, sizeof(lev));
  memset(hchain, -1, sizeof(hchain));
  memset(ichain, -1, sizeof(ichain));
  memset(pib, -1, sizeof(pib));
  tms = nchain = nbase = 0;
  memset(price, 0, sizeof(price));
  memset(sum, 0, sizeof(sum));
  memset(ntra, 0, sizeof(ntra));
}
void dfs(int u) {
  tin[u] = tms++;
  vis[u] = size[u] = 1;
  for (int i = (1); i < (maxe); i++) p[i][u] = p[i - 1][p[i - 1][u]];
  for (int i = (0); i < (int((adj[u]).size())); i++) {
    int v = adj[u][i].first;
    if (!vis[v]) {
      price[v] = adj[u][i].second;
      p[0][v] = u;
      lev[v] = lev[u] + 1;
      dfs(v);
      size[u] += size[v];
    }
  }
  tou[u] = tms++;
}
int lca(int u, int v) {
  if (lev[u] < lev[v]) swap(u, v);
  if (tin[v] <= tin[u] && tou[v] >= tou[u]) return v;
  for (int i = (maxe)-1; i >= (0); i--)
    if (lev[u] - (1 << i) >= lev[v]) u = p[i][u];
  for (int i = (maxe)-1; i >= (0); i--)
    if (p[i][u] != p[i][v]) {
      u = p[i][u];
      v = p[i][v];
    }
  return p[0][u];
}
void hld(int u) {
  if (hchain[nchain] == -1) hchain[nchain] = u;
  ichain[u] = nchain;
  pib[u] = nbase++;
  int tmp = -1;
  for (int i = (0); i < (int((adj[u]).size())); i++) {
    int v = adj[u][i].first;
    if (v != p[0][u]) {
      if (tmp == -1 || size[v] > size[tmp]) tmp = v;
    }
  }
  if (tmp != -1) hld(tmp);
  for (int i = (0); i < (int((adj[u]).size())); i++) {
    int v = adj[u][i].first;
    if (v != p[0][u] && v != tmp) {
      nchain++;
      hld(v);
    }
  }
}
void update(int u, int a, bool dir) {
  int uchain = ichain[u], achain = ichain[a];
  while (1) {
    if (uchain == achain) {
      sum[dir][pib[a] + 1]++;
      sum[dir][pib[u] + 1]--;
      return;
    }
    sum[dir][pib[hchain[uchain]]]++;
    sum[dir][pib[u] + 1]--;
    u = p[0][hchain[uchain]];
    uchain = ichain[u];
  }
}
void solve() {
  scanf("%d", &n);
  for (int i = (0); i < (n - 1); i++) {
    int a, b, x;
    scanf("%d%d%d", &a, &b, &x);
    a--;
    b--;
    adj[a].push_back(make_pair(b, x));
    adj[b].push_back(make_pair(a, -x));
  }
  init();
  dfs(0);
  hld(0);
  int k;
  scanf("%d", &k);
  int prev = 0;
  for (int i = (0); i < (k); i++) {
    int s;
    scanf("%d", &s);
    s--;
    int a = lca(prev, s);
    update(prev, a, 0);
    update(s, a, 1);
    prev = s;
  }
  long long ans = 0;
  for (int i = (1); i < (n); i++) {
    ntra[0][i] = ntra[0][i - 1] + sum[0][i];
    ntra[1][i] = ntra[1][i - 1] + sum[1][i];
  }
  for (int i = (1); i < (n); i++) {
    if (price[i] == 1)
      ans = (ans + ex(2, ntra[0][pib[i]]) - 1) % mod;
    else if (price[i] == -1)
      ans = (ans + ex(2, ntra[1][pib[i]]) - 1) % mod;
  }
  printf("%I64d", ans);
}
int main() {
  solve();
  return 0;
}
