Volleyball Scores

Time limit2sMemory limit512 MB

Summary
Track a sequence of volleyball touches and report the score, or flag a wrong serve.
Level

Medium6 of 10

Topics
Simulation, Implementation
Solved
No attempts yet

Problem

Volleyball has been an Olympic sport since 1964. Two teams of 6 players each (2 players each in beach volleyball) hit a ball back and forth, and a team may touch the ball at most three times before it has to send the ball to the other side. More rules apply, such as the ban on the same player touching the ball twice in a row, so keeping the score is tedious work. Write a program that keeps it.

These are the rules this problem uses. Each team has 6 players. Players 1 to 6 belong to Team A, and players 7 to 12 belong to Team B. The two teams take turns serving, so the team that serves a rally is the team that did not serve the previous rally. Either team may serve the first rally.

The other team wins the point when one of the following happens to your team.

  1. One of your players touches the ball twice in a row.
  2. Players of your team touch the ball at least four times in a row.
  3. The ball touches the ground in your court.
  4. The ball touches the ground out of bounds, and one of your players was the last to touch it.
  5. One of your players touches the ball right after one of your players served it.

A point ends the rally, and the next touch in the sequence is the serve of the next rally.

Given the sequence of touches, find the current score. Serving counts as touching the ball. When a player of the wrong team served at any point, report that instead of the score.

Effects of the net are ignored here, together with a few other details, including the rule that the serving player normally rotates.

Input

The first line contains an integer KK (K≥1K \ge 1), the number of data sets in the file. KK data sets follow, each of this form.

The first line of a data set contains an integer tt (1≤t≤10001 \le t \le 1000). The second line contains tt ball touches separated by one space each.

  • An integer ii (1≤i≤121 \le i \le 12) means that player ii touched the ball. This touch may be a serve.
  • The letter A or the letter B means that the ball touched the ground in the court of Team A or in the court of Team B.
  • The letter X means that the ball touched the ground out of bounds.

The first ball touch of a data set is always an integer, the player who served first. The rally may still be in progress when the sequence ends. Apart from wrong serves, the input never contains an impossible sequence.

Output

For each data set, print "Data Set x:" on a line of its own, where x is the number of the data set counted from 1. On the next line print the score of Team A and the score of Team B, separated by one space. When a player of the wrong team served at any point of the sequence, print "Wrong Serve" on that line instead of the score. Print one blank line between two consecutive data sets.

Examples9

  1. Example 1

    Input
    2
    21
    1 X 9 A 3 7 7 7 3 4 5 B 2 8 11 10 3 4 9 B 12
    7
    1 X 9 A 8 X 7
    
    Expected output
    Data Set 1:
    3 2
    
    Data Set 2:
    Wrong Serve
    
  2. Example 2

    Input
    1
    1
    5
    
    Expected output
    Data Set 1:
    0 0
    
  3. Example 3

    Input
    1
    4
    1 8 8 7
    
    Expected output
    Data Set 1:
    1 0
    
  4. Example 4

    Input
    1
    5
    1 7 8 9 10
    
    Expected output
    Data Set 1:
    1 0
    
  5. Example 5

    Input
    1
    2
    1 2
    
    Expected output
    Data Set 1:
    0 1
    
  6. Example 6

    Input
    2
    3
    1 7 A
    4
    1 8 9 B
    
    Expected output
    Data Set 1:
    0 1
    
    Data Set 2:
    1 0
    
  7. Example 7

    Input
    1
    3
    7 1 X
    
    Expected output
    Data Set 1:
    0 1
    
  8. Example 8

    Input
    1
    4
    1 7 A 2
    
    Expected output
    Data Set 1:
    Wrong Serve
    
  9. Example 9

    Input
    3
    2
    1 7
    6
    7 X 1 2 8 9
    3
    12 6 6
    
    Expected output
    Data Set 1:
    0 0
    
    Data Set 2:
    2 1
    
    Data Set 3:
    0 1