Superstition#8559

Superstition

2 seconds
128 megabytes
Easy

Today is the long-awaited day for all school students - the first holiday for the new school year. Our main heroine Deni is now in grade . She prepared for today - she found that there are stores downtown and she plans to visit some of them with her friends. But Deni and her friends don't like some of the connections between the stores and they won't use them. So they have made a list of pairs of stores such that a pair is from the list if they like the connection from store to and of course they can reach store from and for every pair they have determined the time for travelling the connection (it is the same in both directions). There are no pairs with stores with the same numbers and there are no duplicate pairs.

Deni is very superstitious and one of the superstitions in which she believes is that the total time for travelling must be divisible by . Deni and her friends don't have unlimited time so the maximum time they can spend travelling is . As all girls, Deni is very curious and she starts to count the number of different routes for visiting some of the stores (a store can be visited more than once). Unfortunately, this number can be large so Deni remembers that she knows you - very good programmer and asks you to write the program superstition, which counts the number of valid routes. One route is valid if it uses the connections from the list of pairs, the total time for travelling is divisible by and it is . Two routes are different if there is a difference in the sequences of visited stores. You immediately notice that the answer can be very large and thus Deni tells you that she only wants the remainder when the answer is divided by 1\,000\,000\,007.

Input

From the first line read four integers (2 \leq n \leq 80), (2 \leq m \leq 3160), and (2 \leq d, k \leq 10^9). From each of the next lines read three integers x_i, y_i and t_i - bidirectional connection between x_i and y_i with time of travel t_i (1 \leq t_i \leq 10, 1 \leq i \leq m).

Output

Print the number of different valid routes. Since this number may be quite large, you are required to print its remainder when divided by 1\,000\,000\,007.

Examples

Example 1

Loading
Loading

Example 2

Loading
Loading

Example 3

Loading
Loading