#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100005;
const int mod = 1000000007;
inline int read() {
  int weight = 0, symbol = 1;
  char in = getchar();
  while (!isdigit(in)) {
    if (in == '-') symbol = -1;
    in = getchar();
  }
  while (isdigit(in)) {
    weight = weight * 10 + in - '0';
    in = getchar();
  }
  return symbol * weight;
}
inline void write(int x) {
  int s[20], len = 0;
  if (x < 0) putchar('-'), x = -x;
  do s[++len] = x % 10, x /= 10;
  while (x);
  while (len) putchar('0' | s[len--]);
  putchar(10);
}
inline void Add(long long &x, long long y) { x = (x + y + mod) % mod; }
inline long long Fpow(long long x, int y) {
  long long res = 1;
  while (y) {
    if (y & 1) res = (res * x) % mod;
    x = (x * x) % mod, y >>= 1;
  }
  return res;
}
int n, k;
int pre;
int head[MAXN];
struct EDGE {
  int from, to;
  int next;
  bool has;
} edge[MAXN << 1];
int edge_cnt = 1;
void add_edge(int fr, int to, bool ha) {
  edge[++edge_cnt].from = fr;
  edge[edge_cnt].to = to;
  edge[edge_cnt].has = ha;
  edge[edge_cnt].next = head[fr];
  head[fr] = edge_cnt;
}
int fa[MAXN], siz[MAXN], depth[MAXN];
int dfs_cnt;
int top[MAXN], son[MAXN];
void dfs_son(int x, int fath) {
  depth[x] = depth[fa[x] = fath] + (siz[x] = 1);
  for (int i = head[x]; i; i = edge[i].next) {
    int y = edge[i].to;
    if (y == fath) continue;
    dfs_son(y, x);
    siz[x] += siz[y];
    if (siz[son[x]] < siz[y]) son[x] = y;
  }
}
void dfs_chain(int x, int tp) {
  top[x] = tp;
  if (son[x]) dfs_chain(son[x], tp);
  for (int i = head[x]; i; i = edge[i].next) {
    int y = edge[i].to;
    if (y == fa[x] || y == son[x]) continue;
    dfs_chain(y, y);
  }
}
int lca(int x, int y) {
  while (top[x] != top[y]) {
    if (depth[top[x]] < depth[top[y]]) swap(x, y);
    x = fa[top[x]];
  }
  return (depth[x] < depth[y]) ? x : y;
}
int dmin(int x, int y) { return (depth[x] < depth[y]) ? x : y; }
int dmax(int x, int y) { return (depth[x] > depth[y]) ? x : y; }
int sum[MAXN][2];
void dfs_sum(int x) {
  for (int i = head[x]; i; i = edge[i].next) {
    int y = edge[i].to;
    if (y == fa[x]) continue;
    dfs_sum(y);
    sum[x][0] += sum[y][0], sum[x][1] += sum[y][1];
  }
}
long long ans;
signed main() {
  n = read();
  for (int i = 2; i <= n; i++) {
    int u = read(), v = read(), ha = read();
    add_edge(u, v, 0), add_edge(v, u, ha);
  }
  dfs_son(1, 0), dfs_chain(1, 1);
  k = read(), pre = 1;
  for (int i = 1; i <= k; i++) {
    int x = read();
    if (x == pre) continue;
    int Lca = lca(pre, x);
    sum[Lca][0]--, sum[Lca][1]--;
    sum[x][1]++, sum[pre][0]++;
    pre = x;
  }
  dfs_sum(1);
  for (int i = 2; i <= edge_cnt; i++) {
    if (!edge[i].has) continue;
    Add(ans,
        Fpow(2,
             sum[dmax(edge[i].from, edge[i].to)][edge[i].from < edge[i].to]) -
            1);
  }
  write(ans);
  return 0;
}
