There are multiple test cases in the input file. Each test case starts with four integers N , M , K and T , (1<=N<=100, 0<=M<=500, 0<=K<=9, 0<=T<=100) , the number of planet systems, the number of hyperspace tunnels between them, the pursuing Imperial Star Destroyers, and the maximal allowed time to stay at the same system, respectively. M lines follow, each line describes one of the hyperspace tunnels: four integers U , V , C , and W , (0<=U, V<=N - 1, 1<=C<=10, 1<=W<=1000000) meaning there's a tunnel from U to V , traveling through this path requires W seconds and it is only available every C seconds, starting from time 0 (i.e. 0, C, 2 * C, 3 * C... seconds).
Two successive inputs are separated by a blank line. N = 0, M = 0, K = 0, T = 0 indicates the end of input and should not be processed by your program.