#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:1024000000,1024000000")
using namespace std;
template <class T>
inline bool read(T &n) {
  T x = 0, tmp = 1;
  char c = getchar();
  while ((c < '0' || c > '9') && c != '-' && c != EOF) c = getchar();
  if (c == EOF) return false;
  if (c == '-') c = getchar(), tmp = -1;
  while (c >= '0' && c <= '9') x *= 10, x += (c - '0'), c = getchar();
  n = x * tmp;
  return true;
}
template <class T>
inline void write(T n) {
  if (n < 0) {
    putchar('-');
    n = -n;
  }
  int len = 0, data[20];
  while (n) {
    data[len++] = n % 10;
    n /= 10;
  }
  if (!len) data[len++] = 0;
  while (len--) putchar(data[len] + 48);
}
const int MOD = 1e9 + 7;
const int POW = 18;
bool v[100005];
int n, k, tot, s[1000005], a[100005], d[100005], up[100005], down[100005],
    p[100005][20];
long long ans;
struct node {
  int v, next, op;
} g[200005];
long long calc(long long x) {
  long long t = x, tmp = 2, res = 1;
  while (t) {
    if (t & 1) res = res * tmp % MOD;
    tmp = tmp * tmp % MOD;
    t >>= 1;
  }
  return res;
}
void initlca(int u, int fa, int depth) {
  ::d[u] = depth;
  p[u][0] = fa;
  for (int i = 1; i < 20; i++) p[u][i] = p[p[u][i - 1]][i - 1];
  for (int i = a[u]; i != -1; i = g[i].next) {
    if (g[i].v == fa) continue;
    initlca(g[i].v, u, depth + 1);
  }
}
int lca(int u, int v) {
  if (d[u] > d[v]) {
    std::swap(u, v);
  }
  for (int delta = d[v] - d[u], i = 0; delta != 0; delta >>= 1, i++)
    if (delta & 1) v = p[v][i];
  if (u == v) return u;
  for (int i = 19; i >= 0; i--) {
    if (p[u][i] == p[v][i]) continue;
    u = p[u][i], v = p[v][i];
  }
  return p[u][0];
}
void dfs(int x, int fa) {
  int tmp = a[x];
  while (tmp != -1) {
    int i = g[tmp].v;
    if (i != fa) {
      dfs(i, x);
      if (g[tmp].op == 1) {
        ans = (ans + calc(down[i]) + MOD - 1) % MOD;
      }
      if (g[tmp ^ 1].op == 1) {
        ans = (ans + calc(up[i]) + MOD - 1) % MOD;
      }
      up[x] += up[i];
      down[x] += down[i];
    }
    tmp = g[tmp].next;
  }
}
int main() {
  int head, tail, tt = 0;
  memset(a, -1, sizeof(a));
  scanf("%d", &n);
  tot = 0;
  for (int i = 1; i <= n - 1; i++) {
    int u, v, p;
    scanf("%d%d%d", &u, &v, &p);
    if (p == 0) {
      g[tot].v = v;
      g[tot].op = p;
      g[tot].next = a[u];
      a[u] = tot;
      tot++;
      g[tot].v = u;
      g[tot].op = p;
      g[tot].next = a[v];
      a[v] = tot;
      tot++;
    } else {
      g[tot].v = v;
      g[tot].op = 0;
      g[tot].next = a[u];
      a[u] = tot;
      tot++;
      g[tot].v = u;
      g[tot].op = 1;
      g[tot].next = a[v];
      a[v] = tot;
      tot++;
    }
  }
  initlca(1, 1, 0);
  scanf("%d", &k);
  int pre = -1, now = 1;
  for (int i = 1; i <= n; i++) {
    up[i] = down[i] = 0;
  }
  for (int i = 1; i <= k; i++) {
    scanf("%d", &s[i]);
    pre = now;
    now = s[i];
    int fa = lca(pre, now);
    up[pre]++;
    down[now]++;
    up[fa]--;
    down[fa]--;
  }
  ans = 0;
  dfs(1, 1);
  printf("%I64d\n", ans);
  return 0;
}
