eolymp
bolt
Try our new interface for solving problems
Problems

Battleships

Battleships

Time limit 0.5 seconds
Memory limit 64 MiB

In school, students love to play in the "sea battle". Each player on the board10x10 puts one ship from 4 cells, 2 ships of 3 cells, 3 ships of 2 cells and 4 of the ship from a single cell in a manner that they did not even touch corners. Then one of the players "shoot", calling the issue one of the cells. If the shot did not fall on any of the ships, the result of a "shot" is a "blunder. If the "shot" falls into one of the ships, but this ship has remained part of that is not got no shot, the result is "a shot" - damage to the ship, if all parts of the ship is damaged, the result - the destruction of the ship.

For the school to the championship game of 'battleships' developed by the server on which players download location of their ships and then sent "shots" on enemy ships. Required to write one of the key modules of the server - a program that calculates the results of "rounds".

Input data

In the first line of input contains one integer N (1  ≤  N  ≤  100) – the number of "rounds". The following 10 lines of 10 characters - the location of enemy ships. An empty cell is denoted by '.', And the cell with a part of the ship - the symbol '#'. This is followed by N lines, each line - the number of cells, in which the player made the shot. Cells of the board are numbered by integers from left to right and top to bottom from 1 to 100 (see fig.).

Output data

Output N rows with the results of "rounds". In the i-th row must be the result of the i-th "shot." In the case of a miss to bring the message "missed", damage to the ship – "damaged", the destruction of the ship – "sinked", repeated "shots" in a cage – "repeated".

Examples

Input example #1
3
..####.###
#.........
#.#.......
..#....#..
..#.......
........#.
##...##...
..........
.......#..
...#......
1
11
21
Output example #1
missed
damaged
sinked