Associated Course(s):
DSA-Self Paced with Doubt Assistance
Placement 100

Given **N** * **M** string array of ** O's** and

`X's`

**X**'s

(diagonals not included).**Input:** The first line of input takes the number of test cases T. Then T test cases follow. Each of the T test cases takes 2 input lines. The first line of each test case have two integers N and M.The second line of N space separated strings follow which indicate the elements in the array.

**Output:**

For each testcase, print number of shapes.

**Constraints:**

1 <= T <= 100

1 <= N, M <= 50

**Example:**

**Input:**

2

4 7

OOOOXXO OXOXOOX XXXXOXO OXXXOOO

10 3

XXO OOX OXO OOO XOX XOX OXO XXO XXX OOO

**Output:**

4

6

**Explanation:
Testcase 1: **Given input is like:

OOOO

O

O

So, X with same colour are adjacent to each other vertically for horizontally (diagonals not included). So, there are 4 different groups in the given matrix.

**Testcase 2:** Given input is like:

XXO

OOX

OXO

OOO

XOX

XOX

O**X**O

**XX**O

**XXX**

OOO

So, this matrix has 6 groups with is having adjacent Xs. Total number of groups is 6.

If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.

ShubhamJain18 | 205 |

makeitdonesolo | 140 |

lost_found | 124 |

maggiiiii | 118 |

SahatPrasad1 | 108 |

Bishnu Dev Panda | 777 |

okayboss | 551 |

ShubhamJain18 | 516 |

yk12 | 514 |

makeitdonesolo | 480 |

blackshadows | 5331 |

Ibrahim Nash | 5219 |

akhayrutdinov | 5111 |

mb1973 | 4925 |

Quandray | 4547 |

Login to report an issue on this page.