#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 vertices and edges. The vertices are numbered from 1 to , and the edges are numbered from 1 to . The -th edge connects vertices and , and has a integer weight . Also, You are given an integer and queries. In the -th query, you are given an integer , and you should find the number of integer pairs that satisfy the following conditions:
- ;
- It is possible to move from vertice to vertice only by using edges that satisfy . The operation means the bitwise XOR operation.
Input
In the first line, there are three integers ---denoting the graph has verticles and edges, and the given integer is k. In the following lines, the -th line contains three integers ---denoting the -th edge connects verticles and , and has a integer weight . In the next line, there is a integer , denoting the number of queries. In the following lines, the -th line contains a integer , descibing the -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