#include <bits/stdc++.h>
using namespace std;
struct node {
  vector<pair<int, bool> > ch;
  int parent;
  bool parentCost;
  long long travelsTo, travelsFrom;
  int lcaIndex, lcaPos;
};
node nodes[100100];
int lcaList[100100 * 3];
int lcaSqrtList[100100 * 3 / 500 + 10];
int lcaIdList[100100 * 3];
int listSize, indices;
int n;
void setParent(int node, int parent) {
  nodes[node].parent = parent;
  for (int i = 0; i < nodes[node].ch.size(); i++) {
    if (nodes[node].ch[i].first == parent) {
      nodes[node].parentCost = nodes[node].ch[i].second;
      nodes[node].ch[i] = nodes[node].ch[nodes[node].ch.size() - 1];
      nodes[node].ch.pop_back();
      return;
    }
  }
}
void rootTree(int node) {
  for (int i = 0; i < nodes[node].ch.size(); i++) {
    setParent(nodes[node].ch[i].first, node);
    rootTree(nodes[node].ch[i].first);
  }
}
void printTree(int node, int ident, bool cost) {
  for (int i = 0; i < ident; i++) printf("  ");
  if (cost)
    printf("node #%d (costs down)\n", node + 1);
  else if (nodes[node].parentCost)
    printf("node #%d (costs up)\n", node + 1);
  else
    printf("node #%d\n", node + 1);
  for (int i = 0; i < nodes[node].ch.size(); i++)
    printTree(nodes[node].ch[i].first, ident + 1, nodes[node].ch[i].second);
}
void initLca(int node) {
  nodes[node].lcaIndex = ++indices;
  nodes[node].lcaPos = listSize;
  lcaIdList[listSize] = node;
  lcaList[listSize++] = nodes[node].lcaIndex;
  for (int i = 0; i < nodes[node].ch.size(); i++) {
    initLca(nodes[node].ch[i].first);
    lcaIdList[listSize] = node;
    lcaList[listSize++] = nodes[node].lcaIndex;
  }
}
void initRmq() {
  int fullSegments = listSize / 500;
  for (int i = 0; i < listSize; i++) {
    int seg = i / 500;
    if (i % 500 == 0) lcaSqrtList[seg] = i;
    if (lcaList[i] < lcaList[lcaSqrtList[seg]]) lcaSqrtList[seg] = i;
  }
}
int calcrmq(int start, int end) {
  int startSeg = start / 500 + 1;
  int endSeg = end / 500 - 1;
  int mmin = start;
  for (int i = startSeg; i <= endSeg; i++)
    if (lcaList[lcaSqrtList[i]] < lcaList[mmin]) mmin = lcaSqrtList[i];
  int ee = end;
  if (startSeg * 500 < ee) ee = startSeg * 500;
  for (int i = start; i < ee; i++)
    if (lcaList[i] < lcaList[mmin]) mmin = i;
  int ss = start;
  if ((endSeg + 1) * 500 > ss) ss = (endSeg + 1) * 500;
  for (int i = ss; i <= end; i++)
    if (lcaList[i] < lcaList[mmin]) mmin = i;
  return lcaIdList[mmin];
}
int rmq(int n1, int n2) {
  if (nodes[n1].lcaPos > nodes[n2].lcaPos)
    return calcrmq(nodes[n2].lcaPos, nodes[n1].lcaPos);
  else
    return calcrmq(nodes[n1].lcaPos, nodes[n2].lcaPos);
}
void fixCount(int node) {
  for (int i = 0; i < nodes[node].ch.size(); i++) {
    int c = nodes[node].ch[i].first;
    fixCount(c);
  }
  if (nodes[node].parent != -1) {
    nodes[nodes[node].parent].travelsFrom += nodes[node].travelsFrom;
    nodes[nodes[node].parent].travelsTo += nodes[node].travelsTo;
  }
}
long long pow2(long long count) {
  if (count < 20)
    return (1 << count) % 1000000007;
  else {
    long long half = pow2(count / 2);
    return (half * half * pow2(count % 2)) % 1000000007;
  }
}
long long singleCost(long long count) {
  long long res = pow2(count);
  if (res == 0)
    return 1000000007 - 1;
  else
    return (res - 1);
}
long long getCost(int node, bool costDown) {
  long long res;
  if (costDown)
    res = singleCost(nodes[node].travelsTo);
  else if (nodes[node].parentCost)
    res = singleCost(nodes[node].travelsFrom);
  else
    res = 0;
  for (int i = 0; i < nodes[node].ch.size(); i++)
    res = (res + getCost(nodes[node].ch[i].first, nodes[node].ch[i].second)) %
          1000000007;
  return res;
}
int main() {
  scanf("%d", &n);
  int a, b, c;
  for (int i = 1; i < n; i++) {
    scanf("%d%d%d", &a, &b, &c);
    nodes[a - 1].ch.push_back(make_pair(b - 1, false));
    nodes[b - 1].ch.push_back(make_pair(a - 1, c != 0));
  }
  for (int i = 0; i < n; i++) {
    nodes[i].travelsTo = 0;
    nodes[i].travelsFrom = 0;
  }
  setParent(0, -1);
  rootTree(0);
  nodes[0].parentCost = false;
  initLca(0);
  initRmq();
  int last = 0, next;
  int k;
  scanf("%d", &k);
  for (int i = 0; i < k; i++) {
    scanf("%d", &next);
    next--;
    int lca = rmq(last, next);
    nodes[last].travelsFrom++;
    nodes[next].travelsTo++;
    nodes[lca].travelsFrom--;
    nodes[lca].travelsTo--;
    last = next;
  }
  fixCount(0);
  printf("%I64d\n", getCost(0, false));
  return 0;
}
