#include<bits/stdc++.h>
#define INF 999999999
using namespace std;
int graph[ 100 ] [ 100 ] ;
int path[ 100 ] [ 100 ] ;
void init( )
{
for ( int i= 1 ; i<= 100 ; i++ )
{
for ( int j= 1 ; j<= 100 ; j++ )
{
if ( i== j) graph[ i] [ j] = 0 ;
else graph[ i] [ j] = INF;
path[ i] [ j] = i;
}
}
}
void printpath( int i, int j)
{
if ( i! = j)
printpath( i, path[ i] [ j] ) ;
printf ( " %d" , j) ;
}
int main( )
{
int node, caseno = 0 ;
while ( scanf ( "%d" , & node) && node! = 0 )
{
init( ) ;
int edge, v, cost;
for ( int u= 1 ; u<= node; u++ )
{
scanf ( "%d" , & edge) ;
for ( int i= 0 ; i< edge; i++ )
{
scanf ( "%d %d" , & v, & cost) ;
graph[ u] [ v] = cost;
}
}
int s, d;
scanf ( "%d %d" , & s, & d) ;
for ( int i= 1 ; i<= node; i++ )
{
for ( int j= 1 ; j<= node; j++ )
{
for ( int k= 1 ; k<= node; k++ )
{
if ( graph[ i] [ j] > graph[ i] [ k] + graph[ k] [ j] )
{
graph[ i] [ j] = graph[ i] [ k] + graph[ k] [ j] ;
path[ i] [ j] = path[ k] [ j] ;
}
}
}
}
printf ( "Case %d: Path =" , ++ caseno) ;
printpath( s, d) ;
printf ( "; %d second delay\n " , graph[ s] [ d] ) ;
}
return 0 ;
}
I2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KI2RlZmluZSBJTkYgOTk5OTk5OTk5Cgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKaW50IGdyYXBoWzEwMF1bMTAwXTsKaW50IHBhdGhbMTAwXVsxMDBdOwoKdm9pZCBpbml0KCkKewogICAgZm9yKGludCBpPTE7IGk8PTEwMDsgaSsrKQogICAgewogICAgICAgIGZvcihpbnQgaj0xOyBqPD0xMDA7IGorKykKICAgICAgICB7CiAgICAgICAgICAgIGlmKGk9PWopIGdyYXBoW2ldW2pdID0gMDsKICAgICAgICAgICAgZWxzZSBncmFwaFtpXVtqXSA9IElORjsKICAgICAgICAgICAgcGF0aFtpXVtqXSA9IGk7CiAgICAgICAgfQogICAgfQp9Cgp2b2lkIHByaW50cGF0aChpbnQgaSwgaW50IGopCnsKICAgIGlmKGkhPWopCiAgICAgICAgcHJpbnRwYXRoKGksIHBhdGhbaV1bal0pOwogICAgcHJpbnRmKCIgJWQiLCBqKTsKfQoKaW50IG1haW4oKQp7CiAgICBpbnQgbm9kZSwgY2FzZW5vID0gMDsKICAgIHdoaWxlKHNjYW5mKCIlZCIsICZub2RlKSAmJiBub2RlIT0wKQogICAgewogICAgICAgIGluaXQoKTsKICAgICAgICBpbnQgZWRnZSwgdiwgY29zdDsKICAgICAgICBmb3IoaW50IHU9MTsgdTw9bm9kZTsgdSsrKQogICAgICAgIHsKICAgICAgICAgICAgc2NhbmYoIiVkIiwgJmVkZ2UpOwogICAgICAgICAgICBmb3IoaW50IGk9MDsgaTxlZGdlOyBpKyspCiAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgIHNjYW5mKCIlZCAlZCIsICZ2LCAmY29zdCk7CiAgICAgICAgICAgICAgICBncmFwaFt1XVt2XSA9IGNvc3Q7CiAgICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgaW50IHMsIGQ7CiAgICAgICAgc2NhbmYoIiVkICVkIiwgJnMsICZkKTsKICAgICAgICBmb3IoaW50IGk9MTsgaTw9bm9kZTsgaSsrKQogICAgICAgIHsKICAgICAgICAgICAgZm9yKGludCBqPTE7IGo8PW5vZGU7IGorKykKICAgICAgICAgICAgewogICAgICAgICAgICAgICAgZm9yKGludCBrPTE7IGs8PW5vZGU7IGsrKykKICAgICAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgICAgICBpZihncmFwaFtpXVtqXT5ncmFwaFtpXVtrXStncmFwaFtrXVtqXSkKICAgICAgICAgICAgICAgICAgICB7CiAgICAgICAgICAgICAgICAgICAgICAgIGdyYXBoW2ldW2pdID0gZ3JhcGhbaV1ba10gKyBncmFwaFtrXVtqXTsKICAgICA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