#include <bits/stdc++.h>
using namespace std;
const int maxlg = 20;
const int mod = 1e9 + 7;
int hei[1 << maxlg], par[1 << maxlg][maxlg], t2[1 << maxlg];
vector<int> v[1 << maxlg];
long long ans;
int fir[1 << maxlg], sec[1 << maxlg], dady[1 << maxlg];
bool mark[1 << maxlg];
set<pair<int, int> > myset;
void dfs(int root, int h) {
  mark[root] = true;
  if (h == 0) par[root][0] = root;
  hei[root] = h;
  for (int i = 1; i < maxlg; i++) par[root][i] = par[par[root][i - 1]][i - 1];
  for (int j = 0; j < (int)v[root].size(); j++)
    if (!mark[v[root][j]]) {
      par[v[root][j]][0] = root;
      dfs(v[root][j], h + 1);
    }
}
int lca(int x, int y) {
  if (hei[x] > hei[y]) swap(x, y);
  int lg = maxlg - 1;
  while (hei[x] != hei[y]) {
    if (hei[par[y][lg]] >= hei[x])
      y = par[y][lg];
    else
      lg--;
  }
  for (int j = maxlg - 1; j >= 0; j--)
    if (par[x][j] != par[y][j]) {
      x = par[x][j];
      y = par[y][j];
    }
  return (x == y) ? x : par[x][0];
}
void Ddfs(int root, int curpar) {
  for (auto child : v[root])
    if (child != curpar) {
      Ddfs(child, root);
      fir[root] += fir[child];
      sec[root] += sec[child];
      dady[root] += dady[child];
    }
  long long tmp = 0;
  if (myset.find(pair<int, int>(curpar, root)) != myset.end()) {
    ans = (ans + t2[fir[root] - dady[root]]) % mod;
    tmp = t2[fir[root] - dady[root]];
  }
  if (myset.find(pair<int, int>(root, curpar)) != myset.end()) {
    ans = (ans + t2[sec[root] - dady[root]]) % mod;
    tmp = t2[fir[root] - dady[root]];
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  t2[1] = 1;
  for (int i = 2; i <= 1e6; i++) t2[i] = (t2[i - 1] * 2) % mod;
  for (int i = 2; i <= 1e6; i++) t2[i] = (t2[i - 1] + t2[i]) % mod;
  int n;
  cin >> n;
  for (int i = 1; i < n; i++) {
    int x, y, z;
    cin >> x >> y >> z;
    v[x].push_back(y);
    v[y].push_back(x);
    if (z) myset.insert(pair<int, int>(x, y));
  }
  dfs(1, 0);
  int k, pre;
  cin >> k;
  pre = 1;
  for (int i = 1; i <= k; i++) {
    int x;
    cin >> x;
    fir[pre]++;
    sec[x]++;
    dady[lca(pre, x)]++;
    pre = x;
  }
  Ddfs(1, 1);
  cout << ans << endl;
  return 0;
}
