#Lutece2963. Count Reachable Pairs!

Count Reachable Pairs!

Migrated from Lutece 2963 Count Reachable Pairs!

All parts of this problem, including description, images, samples, data and checker, might be broken. If you find bugs in this problem, please contact the admins.

Description

There is an undirected graph with nn vertices and mm edges. The vertices are numbered from 1 to nn, and the edges are numbered from 1 to mm. The ii-th edge connects vertices uiu_i and viv_i, and has a integer weight wiw_i. Also, You are given an integer kk and qq queries. In the ii-th query, you are given an integer pip_i, and you should find the number of integer pairs (u,v)(u,v) that satisfy the following conditions:

  1. 1u<vn1\le u < v \le n;
  2. It is possible to move from vertice uu to vertice vv only by using edges jj that satisfy wjpi<kw_j \bigoplus p_i < k. The operation \bigoplus means the bitwise XOR operation.

Input

In the first line, there are three integers n,m,kn,m,k---denoting the graph has nn verticles and mm edges, and the given integer is k. In the following mm lines, the ii-th line contains three integers ui,vi,wiu_i,v_i,w_i---denoting the ii-th edge connects verticles uiu_i and viv_i, and has a integer weight wiw_i. In the next line, there is a integer qq, denoting the number of queries. In the following qq lines, the ii-th line contains a integer pip_i, descibing the ii-th query.

Output

For each query print one integer in a line--- the answer for this query.

Samples

10 12 5
1 2 3
2 3 4
3 4 5
4 5 6
5 6 7
6 7 8
7 8 9
9 10 11
1 7 2
5 8 1
3 9 5
4 5 3
7
5
2
0
1
3
1
4
21
6
9
13
9
13
15

Constraints

2n1052\le n\le 10^5 1m,q1051\le m,q\le 10^5 0pi,wj,k<230(1iq,1jm)0\le p_i,w_j,k<2^{30}(1\le i\le q,1\le j\le m)