8533: BBQ

内存限制:128 MB 时间限制:3 S
题面:传统 评测方式:文本比较 上传者:
提交:2 通过:1

题目描述

Today is XllX's birthday. XllX wants to go to barbecue with his good friends. They go to a supermarket and get a lot of food. Then they ride to Laoyingzui, a good place to barbecue outside.

XllX thinks a perfect barbecue string must satisfy the property that it is in a format of abba(just like his name). That is, a perfect barbecue string s satisfies that si=si+3si+1=si+2 (i1(mod4),len0(mod4) ), the index starts from 11 . Note that, empty string is a perfect string.

However, XllX is too busy to prepare the barbecue string. It might not be a perfect string. Now you can modify, add or delete one letter in 1 unit of time. Can you transfer the barbecue string into a perfect string in minimum unit of time?

输入格式

Each test contains multiple test cases. The first line contains the number of test cases(1T12). Description of the test cases follows.

Only one string stands for the barbecue string. It is guaranteed that the length of the string is not greater than 10^6106. All the letters of the string is in lowercase.

输出格式

For each test case:

Print one integer in a line --- the minimum unit of time.

输入样例 复制

1
abbba

输出样例 复制

1