#include <bits/stdc++.h>
using namespace std;
struct edge {
  int to, next, d;
} e[100010 << 1];
int box[100010], cnt;
int siz[100010], top[100010], son[100010], dep[100010], w[100010], fa[100010],
    tot;
void init() {
  memset(box, -1, sizeof(box));
  cnt = tot = 0;
}
void add(int from, int to, int d) {
  e[cnt].to = to;
  e[cnt].d = d;
  e[cnt].next = box[from];
  box[from] = cnt++;
}
void dfs(int now, int pre) {
  siz[now] = 1;
  fa[now] = pre;
  son[now] = 0;
  dep[now] = dep[pre] + 1;
  for (int t = box[now]; t + 1; t = e[t].next) {
    int v = e[t].to;
    if (v != pre) {
      dfs(v, now);
      siz[now] += siz[v];
      if (siz[son[now]] < siz[v]) son[now] = v;
    }
  }
}
void dfs2(int now, int tp) {
  w[now] = ++tot;
  top[now] = tp;
  if (son[now]) dfs2(son[now], top[now]);
  for (int t = box[now]; t + 1; t = e[t].next) {
    int v = e[t].to;
    if (v != fa[now] && v != son[now]) dfs2(v, v);
  }
}
int LCA(int a, int b) {
  while (1) {
    if (top[a] == top[b])
      return dep[a] <= dep[b] ? a : b;
    else if (dep[top[a]] >= dep[top[b]])
      a = fa[top[a]];
    else
      b = fa[top[b]];
  }
}
int vis[100010], Up[100010], Down[100010];
long long Pow(long long a, long long b) {
  if (!b) return 1;
  long long tmp = Pow(a, b / 2);
  tmp = (tmp * tmp) % 1000000007;
  if (b % 2) tmp *= a;
  return tmp % 1000000007;
}
long long dfs3(int now) {
  long long ret = 0;
  vis[now] = 1;
  for (int t = box[now]; t + 1; t = e[t].next) {
    int v = e[t].to, d = e[t].d;
    if (!vis[v]) {
      ret += dfs3(v);
      if (d == 1) {
        ret += Pow(2, Up[v]) - 1;
      } else if (d == -1) {
        ret += Pow(2, Down[v]) - 1;
      }
      Down[now] += Down[v];
      Up[now] += Up[v];
    }
  }
  return ret % 1000000007;
}
int main() {
  int n;
  scanf("%d", &n);
  init();
  for (int i = 1; i < n; i++) {
    int a, b, x;
    scanf("%d%d%d", &a, &b, &x);
    if (x) {
      add(a, b, 1);
      add(b, a, -1);
    } else {
      add(a, b, 0);
      add(b, a, 0);
    }
  }
  dfs(1, -1);
  dfs2(1, 1);
  int k;
  scanf("%d", &k);
  int now = 1;
  long long ans = 0;
  for (int i = 0; i < k; i++) {
    int x;
    scanf("%d", &x);
    int lca = LCA(now, x);
    Up[now] += 1;
    Down[x] += 1;
    Up[lca]--;
    Down[lca]--;
    now = x;
  }
  for (int i = 1; i <= n; i++) {
  }
  ans = dfs3(1);
  cout << ans << endl;
  return 0;
}
