#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
#include <math.h>

struct STRUCT00 {
  int MEMBER00 ;
  int MEMBER01 ;
  int MEMBER02 ;
  int * * MEMBER03 ;
} ;

int VAR00 ;
struct STRUCT00 * VAR01 ;

void FUNC00 ( int * ARG00 , int ARG01 ) ;
int FUNC01 ( int * ARG02 ) ;
void FUNC02 ( int * ARG03 , int ARG04 ) ;
void FUNC03 ( int * ARG05 , int ARG06 ) ;

int main ( int ARG07 , char * ARG08 [ ] )
{
  int VAR02 , VAR03 , VAR04 , VAR05 ;
  int VAR06 , VAR07 , VAR08 ;
  int * VAR09 ;

  VAR00 = 0 ;

  scanf ( "%d" , & VAR02 ) ;
  VAR01 = ( struct STRUCT00 * ) malloc ( sizeof ( struct STRUCT00 ) * VAR02 ) ;
  VAR09 = ( int * ) malloc ( sizeof ( int ) * ( VAR02 + 1 ) ) ;

  for ( VAR03 = 0 ; VAR03 < VAR02 ; VAR03 ++ ) {
    scanf ( "%d" , & VAR05 ) ;
    scanf ( "%d" , & ( VAR01 [ VAR05 ] . MEMBER00 ) ) ;
    VAR01 [ VAR05 ] . MEMBER03 = ( int * * ) malloc ( sizeof ( int * ) * VAR01 [ VAR05 ] . MEMBER00 ) ;
    for ( VAR04 = 0 ; VAR04 < VAR01 [ VAR05 ] . MEMBER00 ; VAR04 ++ ) {
      VAR01 [ VAR05 ] . MEMBER03 [ VAR04 ] = ( int * ) malloc ( sizeof ( int ) * 2 ) ;
      scanf ( "%d" , & ( VAR01 [ VAR05 ] . MEMBER03 [ VAR04 ] [ 0 ] ) ) ;
      scanf ( "%d" , & ( VAR01 [ VAR05 ] . MEMBER03 [ VAR04 ] [ 1 ] ) ) ;
    }
    VAR01 [ VAR05 ] . MEMBER01 = INT_MAX ;
    VAR01 [ VAR05 ] . MEMBER02 = 0 ;

    VAR09 [ VAR00 + 1 ] = VAR05 ;
    VAR00 ++ ;
    FUNC00 ( VAR09 , VAR00 ) ;
  }

  VAR01 [ 0 ] . MEMBER01 = 0 ;
  while ( VAR00 != 0 ) {
    VAR06 = FUNC01 ( VAR09 ) ;
    VAR01 [ VAR06 ] . MEMBER02 = 1 ;
    for ( VAR03 = 0 ; VAR03 < VAR01 [ VAR06 ] . MEMBER00 ; VAR03 ++ ) {
      VAR07 = VAR01 [ VAR06 ] . MEMBER03 [ VAR03 ] [ 0 ] ;
      VAR08 = VAR01 [ VAR06 ] . MEMBER03 [ VAR03 ] [ 1 ] ;
      if ( VAR01 [ VAR07 ] . MEMBER02 == 0 && VAR01 [ VAR07 ] . MEMBER01 > VAR01 [ VAR06 ] . MEMBER01 + VAR08 ) {
 VAR01 [ VAR07 ] . MEMBER01 = VAR01 [ VAR06 ] . MEMBER01 + VAR08 ;
 for ( VAR04 = 1 ; VAR04 <= VAR00 ; VAR04 ++ ) {
   if ( VAR09 [ VAR04 ] == VAR07 ) {
     FUNC02 ( VAR09 , VAR04 ) ;
     break ;
   }
 }
      }
    }
  }

  for ( VAR03 = 0 ; VAR03 < VAR02 ; VAR03 ++ ) printf ( "%d %d\n" , VAR03 , VAR01 [ VAR03 ] . MEMBER01 ) ;

  return 0 ;
}

void FUNC00 ( int * ARG09 , int ARG10 )
{
  int VAR10 , VAR11 ;

  if ( VAR00 == 1 ) return ;
  else FUNC02 ( ARG09 , ARG10 ) ;
}

int FUNC01 ( int * ARG11 )
{
  int VAR12 = ARG11 [ 1 ] , VAR13 ;
  int VAR14 , VAR15 , VAR16 ;

  ARG11 [ 1 ] = ARG11 [ VAR00 -- ] ;

  FUNC03 ( ARG11 , 1 ) ;

  return VAR12 ;
}

void FUNC02 ( int * ARG12 , int ARG13 )
{
  int VAR17 ;
  int VAR18 ;

  VAR17 = ( int ) floor ( ARG13 / 2 ) ;

  while ( VAR17 != 0 && VAR01 [ ARG12 [ VAR17 ] ] . MEMBER01 > VAR01 [ ARG12 [ ARG13 ] ] . MEMBER01 ) {
    VAR18 = ARG12 [ VAR17 ] ;
    ARG12 [ VAR17 ] = ARG12 [ ARG13 ] ;
    ARG12 [ ARG13 ] = VAR18 ;
    ARG13 = VAR17 ;
    VAR17 = ( int ) floor ( ARG13 / 2 ) ;
  }
}

void FUNC03 ( int * ARG14 , int ARG15 )
{
  int VAR19 , VAR20 , VAR21 ;
  int VAR22 ;

  VAR19 = 2 * ARG15 ;
  VAR20 = 2 * ARG15 + 1 ;

  VAR21 = ARG15 ;
  if ( VAR19 <= VAR00 && VAR01 [ ARG14 [ VAR19 ] ] . MEMBER01 < VAR01 [ ARG14 [ ARG15 ] ] . MEMBER01 ) VAR21 = VAR19 ;
  if ( VAR20 <= VAR00 && VAR01 [ ARG14 [ VAR20 ] ] . MEMBER01 < VAR01 [ ARG14 [ VAR21 ] ] . MEMBER01 ) VAR21 = VAR20 ;

  if ( VAR21 != ARG15 ) {
    VAR22 = ARG14 [ VAR21 ] ;
    ARG14 [ VAR21 ] = ARG14 [ ARG15 ] ;
    ARG14 [ ARG15 ] = VAR22 ;
    FUNC03 ( ARG14 , VAR21 ) ;
  }
}


Measured memory_bytes: 21280