C1749 [CCPC2017秦皇岛站-C] Crusaders Quest

内存限制:64 MB 时间限制:1000 ms

题目描述

Crusaders Quest is an interesting mobile game. A mysterious witch has brought great darkness to the game world, and the only hope for your kingdom is to save the Goddesses so that they can unleash their power to fight against the witch.

image.png

In order to save the game world, you need to choose three heroes to fight for victory and use their skills wisely. Nine skill blocks of three different types (three blocks per type) will be presented at the bottom of the screen. If $k(k \ge 1)$ consecutive blocks are of the same type, you can tap on them and eliminate them, thus triggering the powerful skill they represent. After the elimination, the blocks to their left will be connected with the blocks to their right. Moreover, if $k=3$ consecutive blocks of the same type are eliminated, the powerful skill they unleash will be upgraded to a super skill, which is the most powerful skill of all.

DreamGrid is a newbie in this game, and he wants to trigger the super skill as many times as he can. Given nine skill blocks satisfying the description above, please help DreamGrid calculate the maximum number of times he can trigger the super skill.

输入格式

There are multiple test cases. The first line of input contains an integer $T$ (about 50), indicating the number of test cases. For each test case:

The first line contains a string $s(|s|=9)$ consisting of three 'g's, three 'a's and three 'o's, representing the nine skill blocks of three different types. Each type of character represents one type of skill block.

输出

For each test case, output an integer denoting the maximum number of times DreamGrid can trigger the super skill.

样例

样例输入 1

7 gggaaaooo aaoogggoa googgaaao agogaooag goooggaaa gogogoaaa gaogaogao

样例输出 1

3 3 2 1 3 2 1

提示