Technicians in a pathology lab analyze digitized images of slides. An object on a slide is selected for analysis by clicking on it with the mouse. One useful measurement of an object is the length of the perimeter of its boundary. Your task is to compute this perimeter for the selected object.
A digitized slide is given as a rectangular grid of characters. A period . marks empty space, and a capital letter X marks part of an object. Two simple grids:
XX Grid 1 .XXX Grid 2
XX .XXX
.XXX
...X
..X.
X...
An X in a grid square means the entire unit square, including its boundary, belongs to some object. Two Xs are adjacent when their squares touch along an edge or at a corner, so an X is adjacent to the Xs in any of the 8 surrounding squares:
XXX
XXX the center X is adjacent to all 8 surrounding X's
XXX
An object is the set of grid squares of all Xs that can be linked to one another through a chain of adjacent Xs. In Grid 1 every X forms a single object. In Grid 2 there are two objects: one contains only the lower-left square, and all the remaining Xs form the other.
The technician always clicks on an X, which selects the object containing that square. Rows and columns are numbered from 1, starting at the upper-left corner, and the click position is given as a (row, column) pair. In Grid 1 the object can be selected by clicking row 2, column 2. The larger object in Grid 2 can be selected by clicking row 2, column 3; a click on row 4, column 3 would not select it.

The perimeter is the length of the object's boundary. Treat each X as a square one unit on a side. The object in Grid 1 therefore has perimeter $8$ (2 units on each of its four sides). The larger object in Grid 2 has perimeter $18$, as shown in the figure above.
An object never contains a fully enclosed hole, so the patterns on the left below can not occur, while the variations on the right can:
Impossible Possible
XXXX XXXX XXXX XXXX
X..X XXXX X... X...
XX.X XXXX XX.X XX.X
XXXX XXXX XXXX XX.X
..... ..... ..... .....
..X.. ..X.. ..X.. ..X..
.X.X. .XXX. .X... .....
..X.. ..X.. ..X.. ..X..
..... ..... ..... .....
The input contains one or more grids. Each grid is preceded by a line with four integers: the number of rows, the number of columns, and the row and column of the mouse click. All four numbers are in the range 1-20. The rows of the grid follow, one per line, each made up of . and X characters.
The input ends with a line containing four zeros. On any header line the numbers are separated by blanks; the grid rows contain no blanks.
For each grid, output a single line containing the perimeter of the selected object.