1. 
/**
* FWP, Ausgewählte Probleme aus dem ACM Programming Contest, SS11
* @author Beinhofer Christian
* @version 1.0
*
* Flooding-Algorithmus
* 8971062 469 Wetlands of Florida Accepted C++ 0.060 2011-06-20 17:49:15
* Link: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=410
*/

#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>

int lines;
char map[100][100];

int flood(int x, int y)
{
int result = 1, // This one is water and is unchecked, count it!
col, row;

// Just negate the W -> -W to mark a node as checked in the same array
// Next flood of the same area will use -W -> W
char checked = -map[x][y];

map[x][y] = checked; // Set this one checked

for(int c = -1; c < 2; c++)
{
col = x + c;
if(col < 0 || col == lines) continue;
for(int r = -1; r < 2; r++)
{
row = y + r;
if(row < 0 || row == lines) continue;

if(map[col][row] == -checked)
result += flood(col, row);
}
}

return result;
}

int main()
{
int cases;
scanf("%d", &cases);

int x, y, result;
char line[6];

while(cases--)
{
// read the whole map
scanf("%s", map[0]);
for(lines = 1; map[0][lines]; lines++)
scanf("%s", map[lines]);

// get the water coordinates
gets(line);
while(gets(line))
{
if(line[0] == '\0') break;

sscanf(line, "%d %d", &x, &y);
result = flood(x - 1, y - 1);
printf("%d\n", result);
}

if(feof(stdin)) break;
printf("\n", result);
}

return 0;
}