

program MovingRobots ;

 const N = 50 ;
       maxNumOfRobots = 10 ;

 type
        
      RobotState = record
            x, y : integer ;
            dir : 0..3 ;
        end ;
        
      RobotDefinition = record
          cmdsN : integer ;
          cmds : array [ 1.. N ] of record
                    kind : char ;
                    angle : 0..3 ;
                  end ;
          initState : RobotState ;        
        end ;
          
        
      ReachableStates = record
           maxIdx : integer ;
           states : array [ -N..N, -N..N, 0..3 ] of byte ;
           shiftX, shiftY : integer ;
         end ;   
                            
      CommonPositions = record
           isInitialized : boolean ;
           maxIdx : integer ;
           positions : array [ -N..N, -N..N ] of record
                          reachableBy : integer ;
                          len : integer ;
                         end ; 
           shiftX, shiftY : integer ;
         end ;  

 var
      numOfRobots : integer ;
      robots : array [ 1..maxNumOfRobots ] of RobotDefinition ;

      robotRS : ReachableStates ;
      statesBuf : array [ -N..N, -N..N, 0..3 ] of byte ;
      
      commonRP : CommonPositions ;
 
      r : integer ;
      commonCmdsLen : integer ;
      
      optRemoveLen : integer ;
      optX, optY : integer ;
      optLen : integer ;
      
      outputFile : text ;


  procedure readInputData( inputFileName : string ) ;
   var 
     inputFile : text ;
     r : integer ;
     angle : integer ;
     k : integer ;
     
  begin
  
    assign( inputFile, inputFileName ) ;

    reset( inputFile ) ;
    readln( inputFile, numOfRobots ) ;
    for r := 1 to numOfRobots do
     begin
       readln( inputFile, robots[r].initState.x, robots[r].initState.y, angle, robots[r].cmdsN ) ;
       robots[r].initState.dir := angle div 90 ;
       for k := 1 to robots[r].cmdsN do
       begin
         read( inputFile, robots[r].cmds[k].kind ) ;
         if robots[r].cmds[k].kind = 'T' then
          begin
            read( inputFile, angle ) ;
            robots[r].cmds[k].angle := angle div 90 ;
          end ;
         readln( inputFile ) ;  
       end ;    
     end ;
  
    close( inputFile ) ;
  
  end ;
  
  
  procedure findReachableStates( var robot : RobotDefinition ; var robRS : ReachableStates ) ;
  
    var
        steps : array [ 0..3, 0..1 ] of integer ;
        i, j, ii, jj : integer ;
        d, dd : 0..3 ;
        k : integer ;
        ll : integer ;
  
  begin
  
    steps[0,0] := 1 ; steps[0,1] := 0 ; 
    steps[1,0] := 0 ; steps[1,1] := 1 ; 
    steps[2,0] := -1 ; steps[2,1] := 0 ; 
    steps[3,0] := 0 ; steps[3,1] := -1 ; 

    with robot, robRS do
     begin
      for i := -cmdsN to cmdsN do
       for j := -cmdsN to cmdsN do
        for d := 0 to 3 do
          states[i,j,d] := 100 ; (* indicates not reached state *)

      shiftX := initState.x ; shiftY := initState.y ;
      maxIdx := cmdsN ;
      
      states[ 0, 0, initState.dir ] := 0 ;
      
      for k := 1 to cmdsN do
       begin

         for i := -cmdsN to cmdsN do
          for j := -cmdsN to cmdsN do
           for d := 0 to 3 do
            statesBuf[i,j,d] := states[i,j,d] ;

         for i := -cmdsN to cmdsN do
          for j := -cmdsN to cmdsN do
           for d := 0 to 3 do
             if statesBuf[i,j,d] <> 100 then
              begin
                if cmds[k].kind = 'S' then
                 begin
                   ii := i + steps[d,0] ;
                   jj := j + steps[d,1] ;
                   dd := d ;     
                 end
                else
                 begin
                   ii := i ;
                   jj := j ;
                   dd := ( d + cmds[k].angle ) mod 4 ;
                 end ;
                 
                ll := statesBuf[i,j,d] + 1 ;
                
                if ( states[ii,jj,dd] = 100 ) or ( states[ii,jj,dd] < ll ) then
                  states[ii,jj,dd] := ll ;
              end ;   
       end ;
     end ;  
  
  end ; 
  
  
  procedure calcCommonPositions( var robRS : ReachableStates ; var commonRP : CommonPositions ) ;
   var
       i, j, ii, jj : integer ;
       isCommonPos : boolean ;
       bestStateLen : integer ;
       d : 0..3 ;
  
  begin
  
    if not commonRP.isInitialized then
     begin
       commonRP.isInitialized := true ;
        
       commonRP.maxIdx := robRS.maxIdx ;
       commonRP.shiftX := robRS.shiftX ;
       commonRP.shiftY := robRS.shiftY ;
      
       for i := -commonRP.maxIdx to commonRP.maxIdx do
        for j := -commonRP.maxIdx to commonRP.maxIdx do
         begin
           commonRP.positions[i,j].reachableBy := 0 ;
           commonRP.positions[i,j].len := 0 ;
         end ;  
     end ;
    
    for i := -commonRP.maxIdx to commonRP.maxIdx do
     for j := -commonRP.maxIdx to commonRP.maxIdx do
      begin
     
        isCommonPos := true ;
        ii := i + commonRP.shiftX - robRS.shiftX ;
        if not ( ( ii >= -robRS.maxIdx ) and ( ii <= robRS.maxIdx ) ) then
          isCommonPos := false ;
        jj := j + commonRP.shiftY - robRS.shiftY ;
        if not ( ( jj >= -robRS.maxIdx ) and ( jj <= robRS.maxIdx ) ) then
          isCommonPos := false ;
           
        if isCommonPos then
         begin
           bestStateLen := -1 ;
           for d := 0 to 3 do
            begin
             if ( robRS.states[ii,jj,d] <> 100 ) and 
                ( bestStateLen < robRS.states[ii,jj,d] ) then
               bestStateLen := robRS.states[ii,jj,d] ;
            end ;   
               
           if bestStateLen = -1 then
             isCommonPos := false
           else
            begin
              commonRP.positions[i,j].reachableBy := commonRP.positions[i,j].reachableBy + 1 ;
              commonRP.positions[i,j].len := commonRP.positions[i,j].len + bestStateLen ;
            end ; 
         end ;

      end ;
      
  end ;
  
  procedure findOptimalCommonPosition( numOfRobots : integer; var commonRP : CommonPositions; 
                                       var optX, optY :integer ; var optLen :integer ) ;
   var
       i, j : integer ;
    
  begin
  
    optLen := -1 ;  
  
    with commonRP do 
     for i := -maxIdx to maxIdx do
      for j := -maxIdx to maxIdx do
        if positions[i,j].reachableBy = numOfRobots then
         begin
          if optLen < positions[i,j].len then 
           begin
             optLen := positions[i,j].len ;
             optX := i + shiftX ;
             optY := j + shiftY ;
           end ;  
         end ; 
     
  end ;



begin

  readInputData( 'ROBOTS.IN' ) ;
  
  commonRP.isInitialized := false ;
  
  for r := 1 to numOfRobots do
   begin
    findReachableStates( robots[r], robotRS ) ;
    calcCommonPositions( robotRS, commonRP ) ;
   end ; 
   
  findOptimalCommonPosition( numOfRobots, commonRP,
                             optX, optY, optLen ) ;
  
  if ( optLen >= 0 ) then
   begin
    commonCmdsLen := 0 ;
    for r := 1 to numOfRobots do
      commonCmdsLen := commonCmdsLen + robots[r].cmdsN ;

    optRemoveLen := commonCmdsLen - optLen ;
   end ; 
  
  assign( outputFile, 'ROBOTS.OUT' ) ;
  rewrite( outputFile ) ;
  
  if ( optLen = -1 ) then
    writeln( outputFile, -1 )
  else 
   begin
    writeln( outputFile, optRemoveLen ) ;
    writeln( outputFile, optX, ' ', optY ) ;
   end ; 
   
  close( outputFile) ;

end.

