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.
import java.io.*;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;

/**
 * Created by sbabkin on 9/14/2015.
 */
public class SolverB {

    public static void main(String[] args) throws IOException {
        new SolverB().Run();
    }

    BufferedReader br;
    PrintWriter pw;
    StringTokenizer stok;

    private String nextToken() throws IOException {
        while (stok == null || !stok.hasMoreTokens()) {
            stok = new StringTokenizer(br.readLine());
        }
        return stok.nextToken();
    }

    private int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }

    private long nextLong() throws IOException {
        return Long.parseLong(nextToken());
    }

    private double nextDouble() throws IOException {
        return Double.parseDouble(nextToken());
    }

    private void Run() throws IOException {
//        br = new BufferedReader(new FileReader("input.txt"));
//        pw = new PrintWriter("output.txt");
        br=new BufferedReader(new InputStreamReader(System.in));
        pw=new PrintWriter(new OutputStreamWriter(System.out));

        solve();
        pw.flush();
        pw.close();
    }

    class Edge {
        int to;
        int type;

        public Edge(int to, int type) {
            this.to = to;
            this.type = type;
        }
    }

    long del = (long) 1e9 + 7;
    int n;
    List<List<Edge>> edges = new ArrayList<List<Edge>>();
    int[] kolCA;
    int[] kolStart;
    int[] kolFin;
    int[] level;
    int[][] pred;
    long[] pow = new long[1000500];
    long result = 0;

    private void solve() throws IOException {
        n = nextInt();
        for (int i = 0; i < n; i++) {
            edges.add(new ArrayList<Edge>());
        }
        for (int i = 0; i < n - 1; i++) {
            int a = nextInt() - 1;
            int b = nextInt() - 1;
            int type = nextInt();
            edges.get(a).add(new Edge(b, type));
            edges.get(b).add(new Edge(a, -type));
        }
        pred = new int[n][20];
        level = new int[n];
        findPred(0, 0, 0);
        for (int i = 1; i < 20; i++) {
            for (int j = 0; j < n; j++) {
                pred[j][i] = pred[pred[j][i - 1]][i - 1];
            }
        }
        int k = nextInt();
        pow[0] = 0;
        pow[1] = 1;
        for (int i = 2; i < k + 10; i++) {
            pow[i] = (pow[i - 1] << 1) % del;
        }

        int start = 0;
        int fin = 0;
        kolCA = new int[n];
        kolStart = new int[n];
        kolFin = new int[n];
        for (int i = 0; i < k; i++) {
            fin = nextInt() - 1;
            kolStart[start]++;
            kolFin[fin]++;
            int lca = findLCA(start, fin);
            kolCA[lca]++;
            start = fin;
        }

        findResult(0, -1);
        pw.println(result);
    }

    private void findResult(int cur, int pred) {
        for (Edge edge : edges.get(cur)) {
            if (edge.to != pred) {
                findResult(edge.to, cur);
                if (edge.type == 1) {
                    result = (result + pow[kolStart[edge.to] + 1] - 1 + del) % del;
                } else if (edge.type == -1) {
                    result = (result + pow[kolFin[edge.to] + 1] - 1 + del) % del;
                }
                kolStart[cur] += kolStart[edge.to];
                kolFin[cur] += kolFin[edge.to];
            }
        }
        kolStart[cur] -= kolCA[cur];
        kolFin[cur] -= kolCA[cur];
    }

    private int findLCA(int v1, int v2) {
        if (level[v1] > level[v2]) {
            int buf = v1;
            v1 = v2;
            v2 = buf;
        }
        for (int i = 19; i >= 0; i--) {
            if ((1 << i) <= level[v2] - level[v1]) {
                v2 = pred[v2][i];
            }
        }
        for (int i = 19; i >= 0; i--) {
            if (pred[v1][i] != pred[v2][i]) {
                v1 = pred[v1][i];
                v2 = pred[v2][i];
            }
        }
        if (v1 == v2) {
            return v1;
        } else {
            return pred[v1][0];
        }
    }

    private void findPred(int cur, int ans, int curLevel) {
        pred[cur][0] = ans;
        level[cur] = curLevel;
        for (Edge edge : edges.get(cur)) {
            if (edge.to != ans) {
                findPred(edge.to, cur, curLevel + 1);
            }
        }
    }

}
