   import java.util.*;
   import java.lang.*;
   import java.io.*;

    public class Four{
   
       public static void main(String args[]) throws Exception{
         BufferedReader in = new BufferedReader(new FileReader("DATA3.txt"));
         BufferedWriter out = new BufferedWriter(new FileWriter("OUT3.txt"));
              
         for(int i=0;i<10;i++){
            String str = in.readLine();
         }
      		
      		
      		
         int hash[][]={		 
                  {0,11,13,13,11, 11, 12, 13, 12, 11, 13, 13},
                  {0, 0, 8, 16, 14, 6, 7, 8, 9, 10, 8, 16},
                  {0, 0, 0, 18, 8, 9, 10, 11, 12, 13, 6, 18},
                  {0, 0, 0, 0, 8, 12, 11, 10, 9, 8, 18, 6},
                  {0, 0, 0, 0, 0, 10, 9, 8, 7, 6, 16, 8},
                  {0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 8, 12},
                  {0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 9, 11},
                  {0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 10, 10},
                  {0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 11, 9},
                  {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 12, 8},
                  {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 18},
                  {0 ,0 ,0,0,0,0,0,0,0,0,0,0}
                  };
                  
         for(int i=0;i<12;i++){
            for(int j=i;j<12;j++){
               hash[j][i]=hash[i][j];
            }
         }
      		
      		
      		
      		
         for(int k=0;k<5;k++){
            int c=0;
            String str = in.readLine();
            if(str.length()==1){
               out.write("0");
               out.newLine();
               continue;
            }
            
         //System.out.println(str);
         
            for(int i=0;i<str.length()-1;i++){
               c+=hash[str.charAt(i)-'A'][str.charAt(i+1)-'A'];
            }
            out.write(c+"");
            out.newLine();
         }
         
          
         	
         	
         
         
          
          
          
          
          
          
          
          
          
          
         
         
      	
                    
      
         in.close();
         out.close();
      
      }
   }
