#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int inf = 1e9 + 9;
const long long int MOD = 1e9 + 696969;
const long long int INF = 1e18 + 3;
int n, m, a, b, c;
int skok[100100][19], pre[100100], post[100100], DL = 0;
vector<pair<int, int> > v[100100];
bool odw[100100];
vector<pair<int, int> > queries;
int dol[100100], gora[100100];
int KRAW[100100];
long long int potmod(long long int a, long long int b) {
  if (!b) return 1;
  if (b & 1) return a % mod * potmod(a * a % mod, b >> 1) % mod;
  return potmod(a * a % mod, b >> 1) % mod;
}
void dfs(int x) {
  odw[x] = true;
  pre[x] = ++DL;
  for (auto u : v[x])
    if (!odw[u.first]) {
      dfs(u.first);
      skok[u.first][0] = x;
    }
  post[x] = ++DL;
}
inline bool parent(int x, int y) {
  if (pre[x] <= pre[y] && post[x] >= post[y]) return true;
  return false;
}
int lca(int x, int y) {
  if (parent(x, y)) return x;
  if (parent(y, x)) return y;
  for (int j = 19 - 1; j >= 0; --j)
    if (parent(skok[x][j], y) == false) x = skok[x][j];
  return skok[x][0];
}
void wyndfs(int x) {
  odw[x] = true;
  int ile = 0, iledol = 0;
  for (unsigned int i = 0; i < v[x].size(); ++i)
    if (!odw[v[x][i].first]) {
      wyndfs(v[x][i].first);
      if (v[x][i].second == -1) KRAW[v[x][i].first] += gora[v[x][i].first];
      if (v[x][i].second == 1) KRAW[v[x][i].first] += dol[v[x][i].first];
      ile += gora[v[x][i].first];
      iledol += dol[v[x][i].first];
    }
  gora[x] += ile;
  dol[x] += iledol;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i < n; ++i) {
    scanf("%d%d%d", &a, &b, &c);
    if (c)
      v[a].push_back({b, -1}), v[b].push_back({a, 1});
    else
      v[a].push_back({b, 0}), v[b].push_back({a, 0});
  }
  dfs(1);
  skok[1][0] = 1;
  for (int j = 1; j < 19; ++j)
    for (int i = 1; i <= n; ++i) skok[i][j] = skok[skok[i][j - 1]][j - 1];
  int zap, skad = 1;
  scanf("%d", &zap);
  for (int z = 1; z <= zap; ++z) {
    int nowy;
    scanf("%d", &nowy);
    a = skad;
    b = nowy;
    int LCA = lca(a, b);
    queries.push_back({a, LCA});
    queries.push_back({LCA, b});
    skad = nowy;
  }
  fill(odw, odw + n + 1, false);
  for (auto tmp : queries) {
    if (tmp.first == tmp.second) continue;
    int x = tmp.first, y = tmp.second;
    assert(parent(x, y) || parent(y, x));
    if (parent(x, y))
      dol[y]++, dol[x]--;
    else
      gora[x]++, gora[y]--;
  }
  wyndfs(1);
  long long int wyn = 0;
  for (int i = 2; i <= n; ++i) wyn += (potmod(2, KRAW[i]) - 1 + mod) % mod;
  cout << wyn % mod;
}
