#include <bits/stdc++.h>
using namespace std;
int n, m, sol;
int st[20][100010], ts[100010], ds[100010], dj[100010], niv[100010];
int a[100010], b[100010], x[100010], f[100010];
int p2[1000010];
vector<int> v[100010];
void df(int nod, int t) {
  st[0][nod] = t;
  niv[nod] = niv[t] + 1;
  for (int i = 1; st[i - 1][st[i - 1][nod]] != 0; ++i)
    st[i][nod] = st[i - 1][st[i - 1][nod]];
  int fiu, mc;
  f[nod] = 1;
  for (int i = 0; i < v[nod].size(); ++i) {
    mc = v[nod][i];
    if (a[mc] == nod) {
      fiu = b[mc];
      if (f[fiu]) continue;
      if (x[mc] == 1) ts[fiu] = 1;
    } else {
      fiu = a[mc];
      if (f[fiu]) continue;
      if (x[mc] == 1) ts[fiu] = 2;
    }
    df(fiu, nod);
  }
}
void df2(int nod) {
  int fiu, mc;
  f[nod] = 1;
  for (int i = 0; i < v[nod].size(); ++i) {
    mc = v[nod][i];
    if (a[mc] == nod) {
      fiu = b[mc];
      if (f[fiu]) continue;
    } else {
      fiu = a[mc];
      if (f[fiu]) continue;
    }
    df2(fiu);
    ds[nod] += ds[fiu];
    dj[nod] += dj[fiu];
  }
  if (ts[nod] == 2)
    sol = (1LL * sol + p2[dj[nod]] - 1 + 1000000007) % 1000000007;
  if (ts[nod] == 1)
    sol = (1LL * sol + p2[ds[nod]] - 1 + 1000000007) % 1000000007;
}
int lca(int x, int y) {
  if (niv[x] < niv[y]) swap(x, y);
  for (int i = 20 - 1; i >= 0; --i)
    if (niv[st[i][x]] >= niv[y]) x = st[i][x];
  if (x == y) return x;
  for (int i = 20 - 1; i >= 0; --i)
    if (st[i][x] != st[i][y]) {
      x = st[i][x];
      y = st[i][y];
    }
  return st[0][x];
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i < n; ++i) {
    scanf("%d%d%d", &a[i], &b[i], &x[i]);
    v[a[i]].push_back(i);
    v[b[i]].push_back(i);
  }
  df(1, 0);
  int prev = 1, ss, xx;
  scanf("%d", &m);
  for (int i = 1; i <= m; ++i) {
    scanf("%d", &xx);
    ss = lca(prev, xx);
    ds[prev]++;
    ds[ss]--;
    dj[xx]++;
    dj[ss]--;
    prev = xx;
  }
  p2[0] = 1;
  for (int i = 1; i <= m + 1; ++i) p2[i] = (2LL * p2[i - 1]) % 1000000007;
  memset(f, 0, sizeof(f));
  df2(1);
  printf("%d\n", sol);
  return 0;
}
