// Arvind Kannan

// Intermediate

// ACSL Contest #3

// Montgomery Blair High School #2070

 

 

import java.util.Scanner;

public class mancala

{

      public static void main(String[] args)

      {

            int[] num_stones = {4,4,4,4,4,4,0,4,4,4,4,4,4,0};

           

 

           

            for (int over = 1;over < 6;over++)

            {

                  String line = "";

                  int start_index = 0;

                  String direction = "";

                  int print_index = 0;

                  String player = "";

                  int hand_marbles = 0;

           

                  Scanner input_line = new Scanner(System.in);

                  line = input_line.nextLine();

                  String[] temp = line.split(",");

                 

                 

                  if (temp[1].equals("1"))

                  {

                        start_index = 0;

                  }

                  else if (temp[1].equals("2"))

                  {

                        start_index = 1;

                  }

                  else if (temp[1].equals("3"))

                  {

                        start_index = 2;

                  }

                  else if (temp[1].equals("4"))

                  {

                        start_index = 3;

                  }

                  else if (temp[1].equals("5"))

                  {

                        start_index = 4;

                  }

                  else if (temp[1].equals("6"))

                  {

                        start_index = 5;

                  }

                  else if (temp[1].equals("7"))

                  {

                        start_index = 7;

                  }

                  else if (temp[1].equals("8"))

                  {

                        start_index = 8;

                  }

                  else if (temp[1].equals("9"))

                  {

                        start_index = 9;

                  }

                  else if (temp[1].equals("10"))

                  {

                        start_index = 10;

                  }

                  else if (temp[1].equals("11"))

                  {

                        start_index = 11;

                  }

                  else if (temp[1].equals("12"))

                  {

                        start_index = 12;

                  }

                  else if (temp[1].equals("A"))

                  {

                        start_index = 6;

                  }

                  else if (temp[1].equals("B"))

                  {

                        start_index = 13;

                  }

                  //start_index = Integer.parseInt(temp[1]) - 1;

                 

                 

                 

                  //System.out.println(start_index);

                  direction = temp[0];

                  //System.out.print(temp[2]);//

                  if (temp[2].equals("A"))

                  {

                        print_index = 6;

                  }

                  else if (temp[2].equals("B"))

                  {

                        print_index = 13;

                  }

                  else if (temp[2].equals("1"))

                  {

                        print_index = 0;

                  }

                  else if (temp[2].equals("2"))

                  {

                        print_index = 1;

                  }

                  else if (temp[2].equals("3"))

                  {

                        print_index = 2;

                  }

                  else if (temp[2].equals("4"))

                  {

                        print_index = 3;

                  }

                  else if (temp[2].equals("5"))

                  {

                        print_index = 4;

                  }

                  else if (temp[2].equals("6"))

                  {

                        print_index = 5;

                  }

                  else if (temp[2].equals("7"))

                  {

                        print_index = 7;

                  }

                  else if (temp[2].equals("8"))

                  {

                        print_index = 8;

                  }

                  else if (temp[2].equals("9"))

                  {

                        print_index = 9;

                  }

                  else if (temp[2].equals("10"))

                  {

                        print_index = 10;

                  }

                  else if (temp[2].equals("11"))

                  {

                        print_index = 11;

                  }

                  else if (temp[2].equals("12"))

                  {

                        print_index = 12;

                  }

 

                  //System.out.println(start_index);

                  //System.out.println(direction);

                  //System.out.println(print_index);

                 

                 

                  if (over%2 == 1)

                  {

                        player = "A";

                  }

                  else

                  {

                        player = "B";

                  }

                  //System.out.println(player);//

                 

                  hand_marbles = num_stones[start_index];

                  if (direction.equals("R"))

                  {

                        num_stones[start_index] = 0;

                        while (hand_marbles > 0)

                        {

                              if (start_index+1 > 13)

                              {

                                    start_index = 0;

                              }

                              else

                              {

                                    start_index++;

                              }

                              if (player.equals("B") & start_index == 6)

                              {    

                              }

                              else if (player.equals("A") & start_index == 13)

                              {    

                              }

                              else

                              {

                                    hand_marbles--;

                                    num_stones[start_index]++;

                              }

                        }

                  }

                  else if (direction.equals("L"))

                  {

                        num_stones[start_index] = 0;

                        while (hand_marbles > 0)

                        {

                              if (start_index - 1 < 0)

                              {

                                    start_index = 13;

                              }

                              else

                              {

                                    start_index--;

                              }

                              //System.out.println("Index is " + start_index);

                              if (player.equals("B") & start_index == 6)

                              {

                              }

                              else if (player.equals("A") & start_index == 13)

                              {

                              }

                              else

                              {

                                    hand_marbles--;

                                    num_stones[start_index]++;

                              }

                              //System.out.println(num_stones[start_index]);

                        }

                  }

                  //System.out.println(print_index);

                  System.out.println(num_stones[print_index]);

                  //System.out.println(num_stones[6]);// ABANK

                  //System.out.println(num_stones[13]);// BBANK

            }

      }

}