Combine the strings
Submissions: 2915   Accuracy:

14.47%

  Difficulty: Easy   Marks: 2

Given N strings consisting of ‘R’ and ‘B’. Two strings can be only combined if last character of first string and first character of second string are same. Print the maximum length possible by combining strings.

Input:
The first line of input contains an integer T denoting the number of test cases. Then T test cases follow. Each test case consists of two lines. First line of each test case contains an Integer N denoting number of strings and the second line contains N space separated strings of equal length.


Output:
For each test case, in a new line print the maximum length possible. If no strings can combine then print "0".

Constraints:
1<=T<=100
2<=N<=1000

1<=|String length|<=1000

Example:
Input:

2
3
RBR BBR RRR
2
RRR BBB

Output:
9
0

** For More Input/Output Examples Use 'Expected Output' option **

Contributor: Arun Tyagi
Author: arun03


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.



Need help with your code? Please use ide.geeksforgeeks.org, generate link and share the link here.


to report an issue on this page.