#include <bits/stdc++.h>
using namespace std;
const int maxn = (int)2e5;
const int mod = (int)1e9 + 7;
const int logn = 20;
int n, m;
vector<int> g[maxn];
int up[maxn][logn + 1];
int tin[maxn], tout[maxn], timer;
set<pair<int, int> > directed;
int cntUp[maxn], cntDown[maxn];
int sumUp[maxn], sumDown[maxn];
void Dfs(int v, int p) {
  tin[v] = ++timer;
  up[v][0] = p;
  for (int l = 1; l <= logn; ++l)
    if (up[v][l - 1] != -1) up[v][l] = up[up[v][l - 1]][l - 1];
  for (int to : g[v]) {
    if (to == p) continue;
    Dfs(to, v);
  }
  tout[v] = ++timer;
}
bool upper(int u, int v) { return (tin[u] <= tin[v] && tout[u] >= tout[v]); }
int LCA(int u, int v) {
  if (upper(u, v)) return u;
  if (upper(v, u)) return v;
  for (int k = logn; k >= 0; --k)
    if (up[u][k] != -1 && !upper(up[u][k], v)) u = up[u][k];
  return up[u][0];
}
int ans;
int modPow(int a, int n) {
  int r = 1;
  while (n > 0) {
    if (n & 1) r = 1ll * r * a % mod;
    a = 1ll * a * a % mod;
    n >>= 1;
  }
  return r;
}
void go(int v, int parent) {
  sumUp[v] = cntUp[v];
  sumDown[v] = cntDown[v];
  for (int u : g[v]) {
    if (u == parent) continue;
    go(u, v);
    sumUp[v] += sumUp[u];
    sumDown[v] += sumDown[u];
  }
  if (directed.count(make_pair(v, parent))) {
    int k = sumDown[v];
    ans += modPow(2, k) - 1;
    ans %= mod;
    if (ans < 0) ans += mod;
  }
  if (directed.count(make_pair(parent, v))) {
    int k = sumUp[v];
    ans += modPow(2, k) - 1;
    ans %= mod;
    if (ans < 0) ans += mod;
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n - 1; ++i) {
    int u, v, w;
    scanf("%d%d%d", &u, &v, &w);
    --u;
    --v;
    if (w) directed.insert(make_pair(u, v));
    g[u].push_back(v);
    g[v].push_back(u);
  }
  memset(up, -1, sizeof(up));
  Dfs(0, -1);
  int qn;
  scanf("%d", &qn);
  int u = 0;
  for (int i = 0; i < qn; ++i) {
    int v;
    scanf("%d", &v);
    --v;
    int lca = LCA(u, v);
    cntUp[u]++;
    cntUp[lca]--;
    cntDown[v]++;
    cntDown[lca]--;
    u = v;
  }
  go(0, -1);
  cout << ans << endl;
  return 0;
}
