চকোলেট স্ট্রিং ( Chocolate String )

CPU: 1s
Memory: 1024MB


মীরা, গোলু আর গতি তিন বন্ধু। তারা প্রত্যেকেই চকোলেট ভালবাসে। একদিন তেজাজ তাদের জন্য চকোল্যান্ড থেকে এত্তগুলা চকোলেট নিয়ে আসল!

মীরা, গোলু আর গতি এখনো বাচ্চাকাচ্চা, চকোলেট কি করে ভাগাভাগি করে নিতে হয় সে ব্যাপারে তাদের ভাল ধারণা নেই। নিজেদের ভেতরে যেন ঝগড়া না হয়, এ জন্য তারা তেজাজকে ভাগাভাগির দায়িত্ব ধরিয়ে দিতে চাইল। তেজাজের আবার ধাঁধা বেশ পছন্দ। তাই সে তাদেরকে একটা ধাঁধার খেলা খেলতে বলল।

তেজাজ অনেক ধরণের চকোলেট কিনেছে। এরপরে প্রতি ধরণের চকোলেটকে সে ইংরেজি a থেকে z এর মধ্যে অক্ষর দিয়ে চিহ্নিত করেছে। তার কাছে সর্বমোট ২৬ ধরণের চকোলেট আছে। একই ধরণের একাধিক চকোলেট থাকতে পারে। তারপর সে সবগুলো চকোলেটকে একরকম ভাবে সাজিয়ে একটি স্ট্রিংয়ের মত বানাল, তারপর ঘোষণা দিল:

"তোমাদের মধ্যে থেকে মীরাই খেলাটা খেলবে। মীরা স্ট্রিংয়ের শুরু থেকে শূণ্য বা কিছু সংখ্যাক চকোলেট নিয়ে গোলুকে দিতে পারবে। তারপর সে শেষ থেকে শূণ্য বা কিছু সংখ্যক চকোলেট নিয়ে গতিকে দিতে পারবে। বাকি সবগুলো চকোলেট তার। কিন্ত এখানে একটা কথা আছে। মীরাকে একটা জিনিস নিশ্চিত করতে হবে। সেটা হচ্ছে, গোলু আর গতিকে দেবার পর যেই চকোলেটগুলো বাকি থাকে সেগুলো যেন একটি প্যালিনড্রম হয়। অন্যথায়, মীরা এভাবে করে চকোলেট দিতে পারবে না। এবং আবার তাকে শুরু থেকে খেলা আরম্ভ করতে হবে।"

মীরা আবার পেটুক প্রকৃতির। তাই সে এমনভাবে খেলাটা খেলতে চায়, যেন সে সব থেকে বেশি সংখ্যক চকোলেট খেতে পারে।

তুমি কি মীরাকে একটু সাহায্য করবে? তোমাকে যদি চকোলেটের স্ট্রিংটা দেওয়া থাকে, তাহলে তোমাকে বলতে হবে যে মীরা সর্বোচ্চ কতটি চকোলেট খেতে পারে।

প্যালিনড্রম কি জিনিস?

প্যালিনড্রম হলো এমন কিছু অক্ষরের সমুষ্টি, যেগুলোকে উল্টো করলেও বাক্যটি অভিন্ন থাকে।

যেমন ধরো: “MADAM” স্ট্রিংটি একটি প্যালিনড্রম, কেননা সেটিকে উল্টা করলেও সেটি “MADAM” ই থাকে। তবে “ABCD” প্যালিনড্রম নয়, কেননা সেটিকে উল্টা করলে সেটি “DCBA” হয়ে যায়।

Meera, Golu and Goti are three friends. They all love chocolates. So one day, when Tzaz brought lots of chocolate from ChocoLand, they all went crazy for those.

Since Meera, Golu and Goti are still kids, they are unable to decide how to share the chocolates among them. In order to avoid fighting they asked Tzaz to decide for them. Tzaz, being a lover of puzzle, suggested them a game.

He brought different kinds of chocolates. He first assigned each kind a letter from [a-z]. Therefore, he brought at most 26 different kinds of chocolates. There can be multiple chocolates of same kind.

Then he lined up all the chocolates in a random order, forming a string. And said:

“Meera will be the one who will play the game. Meera can take some or none of the consecutive chocolates from the beginning of the string, and give it to Golu. Then she can take some or none of the consecutive chocolates from the end of the string and give it to Goti. The remaining chocolates goes to her. But there is a catch. Meera Must make sure that the remaining string (or chocolates) after giving Golu and Goti their chocolates forms a palindrome. Otherwise it will not be counted as a valid distribution, and she must play the game again from beginning.”

Meera being a big eater, wants to take as many chocolates as possible. So she started to wonder, given the string, what is the maximum number of chocolates she can win?

Can you please help her? Given the string of chocolates, please find the maximum number of chocolates Meera can eat.

What is Palindrome?

Palindrome is a sequence of characters, which remains same when read from backwards.

For example, “MADAM” is palindrome since when it reversed, it is still “MADAM”. “ABCD” is not a palindrome, since when it is read from backwards, it is “DCBA”.


ইনপুটের বর্ণনা

ইনপুটের প্রথম লাইনে থাকবে একটি ধনাত্মক পূর্ণসংখ্যা T ( T <= 100 ), যেটি টেস্টকেসের সংখ্যা নির্দেশ করে। এরপরের T লাইনে একটি করে স্ট্রিং S থাকবে যেটির দৈর্য্য কখনো শূণ্য হবে না আবার ১০৫ এর বেশিও হবে না। স্ট্রিংগুলোতে শুধু ছোট হাতের অক্ষর থাকবে। স্ট্রিংগুলোর শুরুতে, মাঝে কিংবা শেষে কোন স্পেস থাকবে না।

২০ % কেসের জন্য, স্ট্রিং S এর দৈর্য্য সর্বোচ্চ ১০ হবে। ৪০ % কেসের জন্য, স্ট্রিং S এর দৈর্য্য সর্বোচ্চ ১০০ হবে। ৭০ % কেসের জন্য, স্ট্রিং S এর দৈর্য্য সর্বোচ্চ ১০০০ হবে।


Input Specification

The first line contains a positive integer T ( T <= 100 ), number of test case. In the following T lines, there will be a nonempty string S of length at most 105. String will only consist of lowercase letters. String will not have any space in the beginning, end or middle.

For 20% of the test case, length of string S will be at most 10.
For 40% of the test case, length of string S will be at most 100.
For 70% of the test case, length of string S will be at most 1000.


আউটপুটের বর্ণনা

প্রতিটা কেসের জন্য কেসের সংখ্যা প্রিন্ট করো। তারপরে প্রিন্ট করো যে, মীরা সর্বোচ্চ কয়টি চকোলেট খেতে পারবে।


Output Specification

For each case print the case number and then print the maximum number of chocolates Meera can eat.


Sample

InputOutput
4 babad a abcd baaacabbadCase 1: 3 Case 2: 1 Case 3: 1 Case 4: 4

Explanation

In case 1, Meera gives 1 chocolate to Golu from left and 1 chocolate from right to Goti. So remaining string at the end is, “aba”. So she gets 3 chocolates.

In case 2, Golu and Goti gets 0 chocolates, so Meera gets 1 chocolate “a”.

In case 3, one of the possible solution is to give Golu 3 chocolates from beginning and 0 to Goti from end. Afterwards, Meera gets “d”.

In case 4, Golu gets “baaac” from left and Goti gets “d”. So Meera gets “abba”. Which is the largest possible palindromic string.

Problemsetter: Mohammad Samiul Islam