#include <bits/stdc++.h>
using namespace std;
int N;
vector<int> L[100000], W[100000];
int p[17][100000], h[100000];
void dfs(int cur, int par, int curh) {
  p[0][cur] = par;
  h[cur] = curh;
  for (int i = 1; i <= 16; ++i) p[i][cur] = p[i - 1][p[i - 1][cur]];
  for (int i = 0; i < L[cur].size(); ++i) {
    int to = L[cur][i];
    if (to != par) {
      dfs(to, cur, curh + 1);
    }
  }
}
int lca(int u, int v) {
  if (h[u] < h[v]) swap(u, v);
  int dh = h[u] - h[v];
  for (int i = 0; i <= 16; ++i) {
    if (dh >> i & 1) {
      u = p[i][u];
    }
  }
  if (u == v) return u;
  for (int i = 16; i >= 0; --i) {
    if (p[i][u] != p[i][v]) {
      u = p[i][u];
      v = p[i][v];
    }
  }
  return p[0][u];
}
int up[100000], down[100000], p2[1000000 + 1];
long long ans;
int dfs_up(int cur, int par, int w) {
  int ret = up[cur];
  for (int i = 0; i < L[cur].size(); ++i) {
    int to = L[cur][i];
    if (to != par) {
      ret += dfs_up(to, cur, W[cur][i]);
    }
  }
  if (w == 1) {
    ans += p2[ret];
    if (ans >= 1000000007) ans -= 1000000007;
  }
  return ret;
}
int dfs_down(int cur, int par, int w) {
  int ret = down[cur];
  for (int i = 0; i < L[cur].size(); ++i) {
    int to = L[cur][i];
    if (to != par) {
      ret += dfs_down(to, cur, W[cur][i]);
    }
  }
  if (w == -1) {
    ans += p2[ret];
    if (ans >= 1000000007) ans -= 1000000007;
  }
  return ret;
}
int main() {
  scanf("%d", &N);
  for (int i = 1, a, b, dir; i < N; ++i) {
    scanf("%d %d %d", &a, &b, &dir);
    --a;
    --b;
    L[a].push_back(b);
    L[b].push_back(a);
    if (dir == 0) {
      W[a].push_back(0);
      W[b].push_back(0);
    } else {
      W[a].push_back(1);
      W[b].push_back(-1);
    }
  }
  dfs(0, 0, 0);
  int K, cur = 0;
  scanf("%d", &K);
  for (int i = 0, to; i < K; ++i) {
    scanf("%d", &to);
    --to;
    int v = lca(cur, to);
    ++up[cur];
    --up[v];
    ++down[to];
    --down[v];
    cur = to;
  }
  p2[0] = 0;
  for (int i = 1; i <= K; ++i) {
    p2[i] = p2[i - 1] << 1;
    ++p2[i];
    if (p2[i] >= 1000000007) p2[i] -= 1000000007;
  }
  ans = 0;
  dfs_up(0, 0, 0);
  dfs_down(0, 0, 0);
  printf("%I64d\n", ans);
  return 0;
}
