A. Counting Ponds Description Due to recent rains, water has pooled in various places in Farmer John's field, which is represented by a rectangle of N x M (1 <= N <= 1000; 1 <= M <= 1000) squares. Each square contains either water ('W') or dry land ('.'). Farmer John would like to figure out how many ponds have formed in his field. A pond is a connected set of squares with water in them, where a square is considered adjacent to all eight of its neighbors. Given a diagram of Farmer John's field, determine how many ponds he has. Input The first line will contain a single integer giving the number of test instances. In each instance, the first line will give two positive integers N and M separated by a single space. The next N lines will each contain M characters. Each character will either be 'W' or '.' Output For each instance, output the number of ponds in Farmer John's field on a separate line. Sample Input 2 10 12 W........WW. .WWW.....WWW ....WW...WW. .........WW. .........W.. ..W......W.. .W.W.....WW. W.W.W.....W. .W.W......W. ..W.......W. 3 4 WWW. .... ..WW Sample Output 3 Source: http://poj.org/problem?id=2386