Bowling in ACM Town uses only 3 pins. Write a program that computes the score of such a bowling game.
A game consists of 10 frames, and the game score is the sum of the scores of every frame. In each frame except the last (the 10th), you may throw at most twice. However, if your first throw knocks down all 3 pins (a strike), that frame uses only 1 throw.
If the 10th frame is a miss, it uses only 2 throws. But if the 10th frame is a strike or a spare, it uses 3 throws in total, including the bonus throw(s).
The frame scoring rules are:
Because a spare needs the next 1 throw and a strike needs the next 2 throws, the 10th frame may take up to 3 throws when it is a strike or a spare.
For example, if in one game the 18 throws knock down, in order, 1, 2, 1, 0, 3, 1, 1, 3, 3, 2, 1, 1, 2, 2, 1, 3, 1, 1, then the frames split as 1,2 / 1,0 / 3 / 1,1 / 3 / 3 / 2,1 / 1,2 / 2,1 / 3,1,1, the per-frame scores are 4 / 1 / 5 / 2 / 8 / 6 / 4 / 5 / 6 / 5, and the game score is 46.
Your program reads the number of pins knocked down by each throw of one game and computes the game's score.
Note that the input may be invalid. For example, a game that starts with 2, 2 is an error: the first throw knocked down only 2 of the 3 pins, so just 1 pin remains standing, and it is impossible for the second throw to knock down 2 pins. Any input that knocks down more pins than are standing at that moment is treated as an error. The same rule applies to the bonus throws of the 10th frame (when a bonus throw clears all pins, the pins are reset).
The program reads from standard input. The input consists of T test cases with 0<T<100. The first line contains T.
Each test case consists of two lines. The first line gives k, the number of integers on the second line, with 11≤k≤21. The second line contains those k integers: the number of pins knocked down by each throw, each an integer between 0 and 3 inclusive.
For each test case, print the bowling score on its own line, so the number of output lines is exactly T. If a test case's input does not follow the rules, print error on that line instead.