#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100005;
const int mod = 1e9 + 7;
vector<int> rev[MAXN];
vector<int> edg[MAXN];
vector<pair<int, int> > ex;
map<pair<int, int>, long long> weight;
int pow2[2005005];
int fin = 1;
int n;
int fintime[MAXN];
int fbytime[MAXN];
int vis[MAXN];
int findscc[MAXN];
vector<int> scced[MAXN];
vector<int> bi[MAXN];
int scc = 1;
void dfs(int node) {
  vis[node] = 1;
  for (int g : edg[node]) {
    if (vis[g]) continue;
    dfs(g);
  }
  fbytime[fin] = node;
  fintime[node] = fin++;
}
void illu(int node) {
  vis[node] = 1;
  findscc[node] = scc;
  for (int g : rev[node]) {
    if (vis[g]) continue;
    illu(g);
  }
}
map<pair<int, int>, int> seen;
int parent[MAXN][19];
int d[MAXN];
void doit(int node, int prev = 0) {
  d[node] = d[prev] + 1;
  parent[node][0] = prev;
  for (int g : bi[node]) {
    if (g == prev) continue;
    doit(g, node);
  }
}
inline void pre() {
  for (int g = 1; g <= 18; g++) {
    for (int y = 1; y <= n; y++) {
      parent[y][g] = parent[parent[y][g - 1]][g - 1];
    }
  }
}
int downadd[MAXN];
int upadd[MAXN];
int lca(int a, int b) {
  if (a == b) return a;
  if (d[a] > d[b]) swap(a, b);
  for (int g = 18; g >= 0; g--) {
    if (d[parent[b][g]] >= d[a]) b = parent[b][g];
  }
  if (a == b) return a;
  for (int g = 18; g >= 0; g--) {
    if (parent[b][g] == parent[a][g]) continue;
    a = parent[a][g];
    b = parent[b][g];
  }
  return parent[a][0];
}
long long ans = 0;
pair<int, int> finsolve(int node, int prev = 0) {
  int d = 0, u = 0;
  for (int g : bi[node]) {
    if (g == prev) continue;
    pair<int, int> x = finsolve(g, node);
    d += x.first, u += x.second;
  }
  d += downadd[node];
  u += upadd[node];
  if (seen[pair<int, int>(parent[node][0], node)]) {
    ans = (ans + pow2[d] - 1) % mod;
  } else
    ans = (ans + pow2[u] - 1) % mod;
  return pair<int, int>(d, u);
}
int main() {
  pow2[0] = 1;
  for (int g = 1; g <= 2e6 + 303; g++) pow2[g] = (pow2[g - 1] * 2) % mod;
  scanf("%d", &n);
  for (int g = 0; g < n - 1; g++) {
    int a, b, c;
    scanf("%d %d %d", &a, &b, &c);
    if (c == 0) {
      rev[a].push_back(b);
      rev[b].push_back(a);
      edg[a].push_back(b);
      edg[b].push_back(a);
      ex.push_back(pair<int, int>(a, b));
      ex.push_back(pair<int, int>(b, a));
    } else
      ex.push_back(pair<int, int>(a, b)), rev[b].push_back(a),
          edg[a].push_back(b);
  }
  for (int g = 1; g <= n; g++) {
    if (vis[g]) continue;
    dfs(g);
  }
  fin--;
  memset(vis, 0, sizeof(vis));
  for (int g = fin; g >= 1; g--) {
    int node = fbytime[g];
    if (vis[node]) continue;
    illu(node);
    scc++;
  }
  scc--;
  for (pair<int, int> t : ex) {
    int f = findscc[t.first], s = findscc[t.second];
    if (seen[pair<int, int>(f, s)]) continue;
    seen[pair<int, int>(f, s)] = 1;
    scced[f].push_back(s);
    if (!seen[pair<int, int>(s, f)]) bi[f].push_back(s), bi[s].push_back(f);
  }
  doit(1);
  pre();
  int la = findscc[1];
  int q;
  scanf("%d", &q);
  for (int g = 1; g <= q; g++) {
    int no;
    scanf("%d", &no);
    no = findscc[no];
    int t = lca(la, no);
    downadd[la]++;
    downadd[t]--;
    upadd[no]++;
    upadd[t]--;
    la = no;
  }
  finsolve(1);
  printf("%I64d", ans);
  return 0;
}
