package Visit_Department;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.Scanner;
public class Solution {
static int n, m, E, T, maxt, r1, r3;
static float r2, r4;
static float[][] a, xs, mxs;
static float[] p;
static int[] qx = new int[100000], visit, ti;
static float[][] time;
public static void main(String[] args) {
try {
System.setIn(new FileInputStream("input.txt"));
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Scanner scanner = new Scanner(System.in);
for (int t = 1; t <= 10; t++) {
n = scanner.nextInt();
a = new float[n][n];
xs = new float[n][n];
m = scanner.nextInt();
E = scanner.nextInt();
T = scanner.nextInt();
r1 = 0;
r3 = 0;
r2 = 0;
r4 = 0;
for (int i = 0; i < m; i++) {
int x = scanner.nextInt() - 1;
int y = scanner.nextInt() - 1;
a[x][y] = scanner.nextFloat();
}
int ts = T / 10;
time = new float[ts + 1][n];
time[0][0] = 1;
for (int i = 1; i <= ts; i++) {
for (int j = 0; j < n; j++) {
if (time[i - 1][j] != 0) {
for (int k = 0; k < n; k++) {
if (a[j][k] != 0) {
time[i][k] += a[j][k] * time[i - 1][j];
}
}
}
}
}
for (int i = 0; i < n; i++) {
if (time[ts][i] > r2) {
r1 = i + 1;
r2 = time[ts][i];
}
}
int t2 = (T - E) / 10;
for (int i = 0; i < n; i++) {
if (time[t2][i] > r4) {
r3 = i + 1;
r4 = time[t2][i];
}
}
System.out.print("#" + t + " " + r1 + " ");
System.out.printf("%.6f ", r2);
System.out.print(r3 + " ");
System.out.printf("%.6f", r4);
System.out.println();
}
scanner.close();
}
}