#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
int ans;
int fa[100010][18], pow2[1000010], dep[100010], delta[100010][2], b[1000010];
vector<pair<int, int> > e[100010];
namespace input {
int read() {
  char ch;
  for (ch = getchar(); (ch < '0' || ch > '9') && ch != '-';) ch = getchar();
  int d = 0, t = 1;
  if (ch == '-') {
    t = -1;
    ch = getchar();
  }
  for (; ch >= '0' && ch <= '9'; ch = getchar()) d = d * 10 + ch - 48;
  return d * t;
}
}  // namespace input
void dfs1(int k) {
  for (vector<pair<int, int> >::iterator p = e[k].begin(); p != e[k].end(); p++)
    if ((*p).first != fa[k][0]) {
      dep[(*p).first] = dep[k] + 1;
      fa[(*p).first][0] = k;
      dfs1((*p).first);
    }
}
int lca(int x, int y) {
  if (dep[x] < dep[y]) swap(x, y);
  int t = dep[x] - dep[y], k = 0;
  while (t) {
    if (t & 1) x = fa[x][k];
    t >>= 1;
    k++;
  }
  if (x == y) return x;
  k = 16;
  while (k >= 0) {
    if (fa[x][k] != fa[y][k]) {
      x = fa[x][k];
      y = fa[y][k];
    }
    k--;
  }
  return fa[x][0];
}
void dfs2(int k) {
  for (vector<pair<int, int> >::iterator p = e[k].begin(); p != e[k].end(); p++)
    if ((*p).first != fa[k][0]) {
      dfs2((*p).first);
      if ((*p).second < 2) {
        ans = (ans + pow2[delta[(*p).first][(*p).second]] - 1) % mod;
      }
      delta[k][0] += delta[(*p).first][0];
      delta[k][1] += delta[(*p).first][1];
    }
}
int main() {
  int n = input::read();
  for (int i = 1; i < n; i++) {
    int x = input::read(), y = input::read(), z = input::read();
    if (z) {
      e[x].push_back(make_pair(y, 0));
      e[y].push_back(make_pair(x, 1));
    } else {
      e[x].push_back(make_pair(y, 2));
      e[y].push_back(make_pair(x, 2));
    }
  }
  dfs1(1);
  for (int j = 1; j <= 16; j++)
    for (int i = 1; i <= n; i++) fa[i][j] = fa[fa[i][j - 1]][j - 1];
  int k = input::read();
  for (int i = 1; i <= k; i++) b[i] = input::read();
  b[0] = 1;
  memset(delta, 0, sizeof(delta));
  for (int i = 0; i < k; i++) {
    delta[b[i]][0]++;
    delta[b[i + 1]][1]++;
    int k = lca(b[i], b[i + 1]);
    delta[k][0]--;
    delta[k][1]--;
  }
  pow2[0] = 1;
  for (int i = 1; i <= k; i++) pow2[i] = pow2[i - 1] * 2 % mod;
  ans = 0;
  dfs2(1);
  printf("%d\n", ans);
  return 0;
}
