VeryEasy

No attempts yetTime limit1sMemory limit256 MB

Problem

Far away there was a village where all kinds of animals lived together. Every year the village held a festival with several contests, and one of them was Crossword. This year the match is between the rabbit team and the turtle team, and the rules go like this.

  1. The equipment is a standard 15 x 15 board and letter tiles from 'A' to 'Z'. The supply of tiles is unlimited, and each team keeps 7 tiles on its rack.

  2. A round is split into two turns. The rabbit team always plays the second turn.

  3. On the first turn the turtle puts tiles in a row or a column with no gap so that they spell a meaningful word. One of those tiles has to land on the star square.

  4. On the second turn the rabbit adds tiles next to the tiles the turtle placed. Every tile the rabbit puts down has to lie in one line, and every group of letters that ends up adjacent, read across and read down, has to be a meaningful word. The new word has to contain at least one letter that the turtle placed. For example, if CAN is on the board, one of these plays is allowed.

    These plays are not allowed.

  5. To score, add up the value of every tile of the word in the line just played, including the tiles that were already on the board. Tiles put on a special square earn a bonus.

    • Star square: the whole word counts double.
    • 2W square: the whole word counts double.
    • 3W square: the whole word counts triple.
    • 2L square: the tile on that square counts double.
    • 3L square: the tile on that square counts triple.

    Apply the letter multipliers first, then apply the word multipliers to the sum. If the play covers several word multiplier squares, multiply by all of them. Covering one 2W square and one 3W square makes the whole word count six times. A square that a tile already covers gives no bonus.

  6. When the match ends, the team with the highest total wins.

This is the first year the rabbit enters the Crossword contest. It studied the rules closely but forgot to memorize any vocabulary, so it knows only two words, VERY and EASY. Out of pride the rabbit decides to play tiles only in a way that spells VERY or EASY.

Now it is the rabbit's turn. Its play has to satisfy all of the conditions below. A letter group here means letters that sit next to each other with no gap, across or down, extended as far as it goes.

  • The rabbit puts at least one tile from its rack on empty squares. All the tiles it puts down lie in the same row, or all of them lie in the same column.
  • The letter group along the direction of the play reads exactly VERY or EASY. Call it the word the rabbit made. If the rabbit puts down a single tile, it picks one of the two directions as the direction of the play.
  • Every other letter group that contains a tile the rabbit put down reads exactly VERY or EASY, if its length is 2 or more. The rabbit knows no other word.
  • The word the rabbit made contains at least one letter that was already on the board.

Only the word the rabbit made is scored. Each tile on the rack is used at most once. Find the highest score the rabbit can get.

Input

The first line holds the number of test cases T (1 ≤ T ≤ 10). Each test case looks like this.

  1. The first 15 lines describe the board before the rabbit plays. Each line holds 15 characters, and each character is one of the following.
    • An uppercase letter from 'A' to 'Z': that square already holds the tile with that letter.
    • A digit from '1' to '5': an empty special square, where '1' is the star square, '2' is 2W, '3' is 3W, '4' is 2L and '5' is 3L.
    • '-': an empty square that is not special.
  2. Line 16 is a string of length 7, the tiles on the rabbit's rack. Each character is an uppercase letter from 'A' to 'Z'.

The rabbit has at least one legal play with the tiles on its rack. The star square is always the centre of the board, the 8th square of the 8th line. The tiles A, E, R and S are worth 1 point each, and the tiles V and Y are worth 4 points each.

Output

For each test case, print one line with the integer M, the highest score the rabbit can get by playing tiles that spell VERY or EASY.