eolymp
bolt
Try our new interface for solving problems
Problems

Superstition

Superstition

Time limit 2 seconds
Memory limit 128 MiB

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 10. She prepared for today - she found that there are n 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 m pairs of stores such that a pair (x, y) is from the list if they like the connection from store x to y and of course they can reach store x from y 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 d. Deni and her friends don’t have unlimited time so the maximum time they can spend travelling is k. 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 visitted 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, thetotal time for travelling is divisible by d and it is ≤ k. 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 data

From the first line read four integers n (2n80), m (2m3160), d and k (2d, k10^9). From each of the next m 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] (1t[i]10, 1im).

Output data

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

Examples

Input example #1
3 3 2 2
1 2 1
2 3 2
3 1 1
Output example #1
8
Input example #2
5 7 5 10
1 3 8
2 5 7
3 4 3
1 4 2
2 3 1
1 5 4
4 5 4
Output example #2
58
Input example #3
5 9 2 20
1 2 1
2 3 2
3 1 1
3 4 1
4 5 2
5 3 1
1 5 1
2 4 1
2 5 1
Output example #3
989802661
Source 2017 IX International autumn tournament in informatics, Shumen, Senior, Day 1, Problem C