Running in Circles

아직 제출이 없습니다메모리 제한1024 MB

문제

Ada has decided that this year, she will take part in the annual marathon that takes place in her city. Since this is the first time she would be running such a long distance, she has decided to start practising for it by running in the circular track of length L\mathbf{L} units near her house.

Ada wants to focus only on running, so she decides to use a machine to count the number of laps she has run. The machine is placed at the starting line of the circular track and starts the count from 00. Every time Ada arrives at the starting line running in the same direction as the last time she departed from the starting line, the machine increases the number of laps that Ada has run by 11. If she crosses the starting line or changes direction at the starting line, the machine considers the new direction as the direction she last touched the starting line. The machine only remembers the last direction in which Ada touched the starting line. During a lap, Ada can change directions any number of times, but as long as she eventually touches the starting line in the same direction as she last touched it, the count of laps in the machine increases by 11.

This is the first time Ada has practised running long distances, so she cannot run continuously. She runs some distance, then takes a break to regain her energy. However, when she starts running again after taking a break, she cannot remember which direction she was running in previously. So she picks one of the directions, clockwise or anticlockwise, and starts running from the same position where she stopped.

Ada begins at the starting line and is initially facing in the direction of her first run. She runs a total of N\mathbf{N} times, taking breaks in between. Given the information of the distance D_i\mathbf{D\_i} units Ada has run, and the direction C_i\mathbf{C\_i} she has taken (clockwise or anticlockwise) when she ran the ii-th time, for all ii from 1,,N1, \dots, \mathbf{N}, can you tell the number of laps that would be reported by the machine at the end?

입력

The first line of the input gives the number of test cases, T\mathbf{T}. T\mathbf{T} test cases follow.

The first line of each test case contains two positive integers L\mathbf{L} and N\mathbf{N}, the length of the circular track in units, and the number of times Ada has run respectively.

The next N\mathbf{N} lines describe Ada's runs. The ii-th line contains a positive integer D_i\mathbf{D\_i} and a character C_i\mathbf{C\_i}, the distance in units Ada has run and the direction she has taken (clockwise or anticlockwise) respectively during the ii-th run. C_i\mathbf{C\_i} will always be either 'C' (denoting clockwise direction) or 'A' (denoting anticlockwise direction).

출력

For each test case, output one line containing Case #x: y, where xx is the test case number (starting from 1) and yy is a non negative integer denoting the number of laps reported by the machine at the end.

제한

  • 1T1001 \le \mathbf{T} \le 100.
  • 1L1091 \le \mathbf{L} \le 10^9.
  • 1N1041 \le \mathbf{N} \le 10^4.
  • 1D_i1091 \le \mathbf{D\_i} \le 10^9, for all 1iN1 \le i \le \mathbf{N}.