#include <iostream>
#include <stdio.h>
using namespace std;
double mt[201][201];
double arr[201][201];
void sub(int n, int t){
arr[0][1] = 1;
int r = 0;
while(r<t/10){
for(int j=1; j<=n; j++){
if(arr[r][j] != 0){
for(int k=1; k<=n; k++){
if(mt[j][k]!=0){
arr[r+1][k] += (mt[j][k] * arr[r][j]);
}
}
}
}
++r;
}
}
int main(){
freopen("vao.txt", "r", stdin);
for(int tc=1; tc<=1; tc++){
cout << "#" << tc << " ";
int n, e, k, t;
cin >> n >> e >> k >> t;
for(int i=0; i<=n; i++){
for(int j=0; j<=n; j++){
arr[i][j] = 0;
}
}
for(int i=0; i<=t/10; i++){
for(int j=0; j<=n; j++){
mt[i][j] = 0;
}
}
int x, y;
double p;
for(int i=0; i<e; i++){
cin >> x >> y >> p;
mt[x][y] = p;
}
for(int i=0; i<= t/10; i++){
for(int j=1; j<=n; j++){
cout << arr[i][j] << " ";
}
cout << endl;
}
sub(n, t);
for(int i=0; i<= t/10; i++){
for(int j=1; j<=n; j++){
cout << arr[i][j] << " ";
}
cout << endl;
}
double maxXS1 = 0;
int room1 = 0;
for(int i=1; i<=n; i++){
if(maxXS1 < arr[t/10][i]){
maxXS1 = arr[t/10][i];
room1 = i;
}
}
double maxXS2 = 0;
int room2 = 0;
for(int i=1; i<=n; i++){
if(maxXS2 < arr[(t-k)/10][i]){
maxXS2 = arr[(t-k)/10][i];
room2 = i;
}
}
cout << "#" << tc << " ";
printf("%d %.6f %d %.6f\n", room1, maxXS1, room2, maxXS2);
}
return 0;
}