#include <bits/stdc++.h>
using namespace std;
const int MAX_N = (int)1e5 + 10;
const int mod = (int)1e9 + 7;
const int N = MAX_N;
int parent[N], P[N][20], level[N];
inline void init(int x, int n) {
  for (int i = 0; i < 20; i++) P[x][i] = -1;
  P[x][0] = parent[x];
  for (int j = 1; (1 << j) < n; j++)
    if (P[x][j - 1] != -1) P[x][j] = P[P[x][j - 1]][j - 1];
}
inline int lca(int x, int y) {
  if (level[x] < level[y]) swap(x, y);
  int lg = 1;
  while ((1 << lg) <= level[x]) lg++;
  lg--;
  for (int i = lg; i >= 0; i--) {
    if (level[x] - (1 << i) >= level[y]) x = P[x][i];
  }
  if (x == y) return x;
  for (int i = lg; i >= 0; i--) {
    if (P[x][i] != -1 && P[x][i] != P[y][i]) x = P[x][i], y = P[y][i];
  }
  return parent[x];
}
vector<int> adj[MAX_N];
int n;
void dfsLca(int u, int par = -1, int lev = 0) {
  parent[u] = par;
  level[u] = lev;
  init(u, n);
  for (int v : adj[u])
    if (v != par) dfsLca(v, u, lev + 1);
}
int up[MAX_N], dn[MAX_N];
set<pair<int, int> > directedEdges;
inline void update(int u, int v) {
  if (u == v) return;
  int anc = lca(u, v);
  if (anc == u) {
    dn[u] -= 1;
    dn[v] += 1;
  } else if (anc == v) {
    up[u] += 1;
    up[v] -= 1;
  } else {
    up[u] += 1;
    up[anc] -= 1;
    dn[v] += 1;
    dn[anc] -= 1;
  }
}
inline int powMod(int x, int n) {
  int ret = 1;
  while (n > 0) {
    if (n & 1) ret = (long long)ret * x % mod;
    x = (long long)x * x % mod;
    n >>= 1;
  }
  return ret;
}
inline void add(int& x, int y) {
  x += y;
  if (x >= mod) x -= mod;
  if (x < 0) x += mod;
}
inline int calcCost(int n) { return (powMod(2, n) - 1 + mod) % mod; }
int ans = 0;
int calcUp(int u, int par = -1) {
  int ret = 0;
  for (int v : adj[u])
    if (v != par) {
      int cur = calcUp(v, u);
      if (directedEdges.count(make_pair(u, v))) {
        add(ans, calcCost(cur));
      }
      ret += cur;
    }
  ret += up[u];
  return ret;
}
int calcDn(int u, int par = -1) {
  int ret = 0;
  for (int v : adj[u])
    if (v != par) {
      int cur = calcDn(v, u);
      if (directedEdges.count(make_pair(v, u))) {
        add(ans, calcCost(cur));
      }
      ret += cur;
    }
  ret += dn[u];
  return ret;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n;
  for (int i = 0; i < n - 1; ++i) {
    int u, v, dir;
    cin >> u >> v >> dir;
    --u, --v;
    adj[u].push_back(v);
    adj[v].push_back(u);
    if (dir == 1) directedEdges.insert(make_pair(u, v));
  }
  int k;
  cin >> k;
  vector<int> city(k);
  for (int i = 0; i < k; ++i) {
    cin >> city[i];
    --city[i];
  }
  dfsLca(0);
  update(0, city[0]);
  for (int i = 1; i < k; ++i) update(city[i - 1], city[i]);
  calcUp(0);
  calcDn(0);
  cout << ans << "\n";
  return 0;
}
