Tarot scores

A hand in the game oftarot Tarot is a card game played in France. It is played with a 78-card deck, composed with 21 trump cards (named one, two, ..., twenty-one), a special card (named the fool) and four suits (spades, hearts, dia- monds, clubs). Each suit has fourteen cards: ten pip cards (ace, two, . . ., ten), and four face cards: jack, knight, queen and king. Three cards have a special status. They are called the oudlers and are the fool, the 1 of trumps and the 21 of trumps. The game is composed of a bidding phase, followed by a main phase. The bidding phase consists in choosing one of the players as the "taker". In the main phase, the players play tricks and try to win as many cards as possible. The outcome of a game is determined by the number of points won by the taker, which is the sum of the values of the cards won by the taker. The value that the taker needs to achieve depends on the number of oudlers he has won throughout the game: • 3 oudlers: 36 points, • 2 oudlers: 41 points, • 1 oudlers: 51 points, • no oudlers: 56 points, The value of each card is as follows: • kings and oudlers: 412 points, • queens: 312 points, • knights: 212 points, • jacks: 112 points, • all other cards: 12 point. For instance, imagine that, at the end of the game, the taker has won the following four cards: ace of spades, eight of diamonds, fool and twenty-one of trumps. Two of these cards are oudlers, so the number of points that the taker needs to score to win is 41. However the sum of the points earned is only 10, and the taker has lost, since the total is 31 points short of the required total. You have to write a program that, given the list of cards won by the taker, indicates if the taker has won her bid, and the number of points she has in excess, or lost and the number of missing points. Input The first line of input gives the number of cases, T (1 ≤ T ≤ 100). T test cases follow. Each one contains an even integer M (0 ≤ M ≤ 78), representing the number of cards won by the taker. Then M lines follow each with a string representing a card (see sample input).

2/3 Output For each test case, output the score. The score of the n-th game starts with the header ‘Hand #n’, on a line of its own, followed by the result (see sample output for the exact syntax), also one a line of its own. The scores are separated by blank lines Sample Input 2 4 ace of spades eight of diamonds fool twenty-one of trumps 42 ace of diamonds ace of hearts eight of clubs eight of diamonds eight of spades eight of trumps eleven of trumps five of clubs five of diamonds four of clubs four of spades four of trumps fourteen of trumps jack of clubs jack of hearts jack of spades king of clubs king of hearts knight of clubs knight of diamonds knight of hearts nine of diamonds nineteen of trumps one of trumps queen of clubs queen of diamonds queen of spades seven of spades seven of trumps six of clubs six of hearts six of trumps sixteen of trumps ten of clubs ten of diamonds three of clubs

3/3 three of diamonds three of hearts three of spades three of trumps two of diamonds two of spades Sample Output Hand #1 Game lost by 31 point(s). Hand #2 Game won by 0 point(s).