#include <bits/stdc++.h>
using namespace std;
vector<vector<int> > g;
set<pair<int, int> > one_way;
int up[100005][18];
int t_in[100005], t_out[100005];
int t;
int d[100005], u[100005];
int pw2[1000005];
int ans;
void dfs(int v, int p = 0) {
  t_in[v] = t++;
  up[v][0] = p;
  for (int i(0), _l((int)(17) - 1); i <= _l; ++i)
    up[v][i + 1] = up[up[v][i]][i];
  for (int i(0), _l((int)(((int)g[v].size())) - 1); i <= _l; ++i) {
    int to(g[v][i]);
    if (to == p) continue;
    dfs(to, v);
  }
  t_out[v] = t++;
}
bool upper(int a, int b) { return t_in[a] <= t_in[b] && t_out[a] >= t_out[b]; }
int lca(int a, int b) {
  if (upper(a, b)) return a;
  if (upper(b, a)) return b;
  for (int i(17); i >= 0; --i)
    if (!upper(up[a][i], b)) a = up[a][i];
  return up[a][0];
}
void process(int a, int b, int k) {
  if (k == 0) return;
  if (one_way.count(make_pair(b, a))) {
    int add(pw2[k]);
    add -= 1;
    if (add < 0) add += 1000000007;
    ans = (ans + add) % 1000000007;
  }
}
pair<int, int> dfs2(int v, int p = 0) {
  pair<int, int> tot(0, 0);
  for (int i(0), _l((int)(((int)g[v].size())) - 1); i <= _l; ++i) {
    int to(g[v][i]);
    if (to == p) continue;
    pair<int, int> nw(dfs2(to, v));
    process(v, to, nw.first);
    process(to, v, nw.second);
    tot.first += nw.first;
    tot.second += nw.second;
  }
  return make_pair(tot.first + d[v], tot.second + u[v]);
}
void solve() {
  int n;
  scanf("%d", &n);
  g.resize(n);
  for (int i(0), _l((int)(n - 1) - 1); i <= _l; ++i) {
    int a, b, c;
    scanf("%d%d%d", &a, &b, &c);
    --a, --b;
    g[a].push_back(b);
    g[b].push_back(a);
    if (c == 1) one_way.insert(make_pair(a, b));
  }
  dfs(0);
  int k;
  scanf("%d", &k);
  int now(0);
  for (int i(0), _l((int)(k)-1); i <= _l; ++i) {
    int a;
    scanf("%d", &a);
    --a;
    int l(lca(now, a));
    u[now] += 1;
    u[l] -= 1;
    d[a] += 1;
    d[l] -= 1;
    now = a;
  }
  pw2[0] = 1;
  for (int i(1), _l(1000000); i <= _l; ++i)
    pw2[i] = (pw2[i - 1] * 2) % 1000000007;
  dfs2(0);
  printf("%d\n", ans);
}
int main() {
  solve();
  return 0;
}
