
In school, students enjoy playing the game "Battleships" (also called "sea battle"). Each player places the following ships on a 10 \times 10 board: one ship occupying cells, two ships of cells, three ships of cells, and four ships each occupying a single cell, in such a way that no two ships touch, not even at the corners.
During the game, one player announces a "shot" by specifying the number of a cell. If the shot does not hit any ship, the result is "missed". If the shot hits a ship but there are still undamaged parts of that ship remaining, the result is "damaged". If the shot hits the last remaining part of a ship, the result is "sinked". If a cell is shot at more than once, the result is "repeated" for all subsequent shots to that cell.
A server is developed for the school's Battleships championship. Players upload the arrangement of their ships and then send their shots at the opponent's board. You are asked to write a program, which for each shot, outputs the appropriate result.
The first line contains an integer (1 \le N \le 100) — the number of shots. Next follow lines of characters each, describing the placement of the opponent's ships. An empty cell is denoted by the character ".", and a cell containing part of a ship is denoted by "#". Then lines follow, each containing the number of the cell targeted by a shot. Cells are numbered from to , left to right and top to bottom (see fig.).
Print lines, each containing the result of the corresponding shot. For each -th shot, output its result:
If it is a miss, print missed;
If it damages a ship, but the ship is not yet destroyed, print damaged;
If it destroys a ship, print sinked;
If this cell was already shot at before, print repeated.
Example 1