Ruritania is a country with a very badly maintained road network, which is not exactly good news for lorry drivers that constantly have to do deliveries. In fact, when roads are maintained, they become one-way. It turns out that it is sometimes impossible to get from one town to another in a legal way – however, we know that all towns are reachable, though illegally!

Fortunately for us, the police tend to be very corrupt and they will allow a lorry driver to break the rules and drive in the wrong direction provided they receive ‘a small gift’. There is one patrol car for every road and they will request 1000 Ruritanian dinars when a driver drives in the wrong direction. However, being greedy, every time a patrol car notices the same driver breaking the rule, they will charge double the amount of money they requested the previous time on that particular road.

Borna is a lorry driver that managed to figure out this bribing pattern. As part of his job, he has to make K stops in some towns all over Ruritania and he has to make these stops in a certain order. There are N towns (enumerated from 1 to N) in Ruritania and Borna’s initial location is the capital city i.e. town 1. He happens to know which ones out of the N - 1 roads in Ruritania are currently unidirectional, but he is unable to compute the least amount of money he needs to prepare for bribing the police. Help Borna by providing him with an answer and you will be richly rewarded.

Input

The first line contains N, the number of towns in Ruritania. The following N - 1 lines contain information regarding individual roads between towns. A road is represented by a tuple of integers (a,b,x), which are separated with a single whitespace character. The numbers a and b represent the cities connected by this particular road, and x is either 0 or 1: 0 means that the road is bidirectional, 1 means that only the a → b direction is legal. The next line contains K, the number of stops Borna has to make. The final line of input contains K positive integers s1, …, sK: the towns Borna has to visit.

  * 1 ≤ N ≤ 105
  * 1 ≤ K ≤ 106
  * 1 ≤ a, b ≤ N for all roads 
  * <image> for all roads 
  * 1 ≤ si ≤ N for all 1 ≤ i ≤ K

Output

The output should contain a single number: the least amount of thousands of Ruritanian dinars Borna should allocate for bribes, modulo 109 + 7.

Examples

Input

5
1 2 0
2 3 0
5 1 1
3 4 1
5
5 4 5 2 2


Output

4

Note

Borna first takes the route 1 → 5 and has to pay 1000 dinars. After that, he takes the route 5 → 1 → 2 → 3 → 4 and pays nothing this time. However, when he has to return via 4 → 3 → 2 → 1 → 5, he needs to prepare 3000 (1000+2000) dinars. Afterwards, getting to 2 via 5 → 1 → 2 will cost him nothing. Finally, he doesn't even have to leave town 2 to get to 2, so there is no need to prepare any additional bribe money. Hence he has to prepare 4000 dinars in total.
#include <bits/stdc++.h>
using namespace std;
inline long long read() {
  register long long x = 0, f = 1;
  register char c = getchar();
  for (; !isdigit(c); c = getchar())
    if (c == '-') f = -1;
  for (; isdigit(c); c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48);
  return x * f;
}
struct Edge {
  long long to, nxt, type;
  Edge() {}
  Edge(long long to, long long nxt, long long type)
      : to(to), nxt(nxt), type(type) {}
} edge[100099 * 2];
long long first[100099], nume;
void Addedge(long long a, long long b, long long c) {
  edge[nume] = Edge(b, first[a], c);
  first[a] = nume++;
}
long long fa[100099], son[100099], size[100099], up[100099], down[100099],
    top[100099], n;
long long deep[100099];
long long Pow[1000009];
void dfs1(long long u, long long f) {
  size[u] = 1;
  son[u] = 0;
  for (long long e = first[u]; ~e; e = edge[e].nxt) {
    long long v = edge[e].to;
    if (v != f) {
      deep[v] = deep[u] + 1;
      dfs1(v, u);
      size[u] += size[v];
      fa[v] = u;
      if (size[son[u]] < size[v]) son[u] = v;
    }
  }
}
void dfs2(long long u, long long chain) {
  top[u] = chain;
  if (son[u]) dfs2(son[u], chain);
  for (long long e = first[u]; ~e; e = edge[e].nxt) {
    long long v = edge[e].to;
    if (v != son[u] && v != fa[u]) dfs2(v, v);
  }
}
long long lca(long long x, long long y) {
  while (top[x] != top[y])
    if (deep[top[x]] > deep[top[y]])
      x = fa[top[x]];
    else
      y = fa[top[y]];
  return deep[x] > deep[y] ? y : x;
}
long long ans;
void dfs(long long u) {
  for (long long e = first[u]; ~e; e = edge[e].nxt) {
    long long v = edge[e].to;
    if (v == fa[u]) continue;
    dfs(v);
    if (edge[e].type == 1)
      ans = (ans + Pow[up[v]] - 1 + 1000000007) % 1000000007;
    if (edge[e].type == 2)
      ans = (ans + Pow[down[v]] - 1 + 1000000007) % 1000000007;
    up[u] += up[v];
    down[u] += down[v];
  }
}
signed main() {
  n = read();
  Pow[0] = 1;
  for (long long i = 1; i <= 1000000; i++)
    Pow[i] = 1LL * Pow[i - 1] * 2 % 1000000007;
  memset(first, -1, sizeof(first));
  nume = 0;
  for (long long i = 1; i < n; i++) {
    long long a = read(), b = read(), c = read();
    if (!c) {
      Addedge(a, b, 0);
      Addedge(b, a, 0);
    } else {
      Addedge(a, b, 1);
      Addedge(b, a, 2);
    }
  }
  size[0] = 0;
  deep[1] = 0;
  dfs1(1, 0);
  dfs2(1, 1);
  memset(up, 0, sizeof(up));
  memset(down, 0, sizeof(down));
  long long K = read();
  long long last = 1;
  for (long long i = 1; i <= K; i++) {
    long long now = read();
    long long tmp = lca(last, now);
    up[last]++;
    up[tmp]--;
    down[now]++;
    down[tmp]--;
    last = now;
  }
  ans = 0;
  dfs(1);
  printf("%I64d\n", ans);
  return 0;
}
