Under construction

Still being built. Things may change

Palindromic Partitions

Time limit10sMemory limit128 MB

Summary
Split a string into chunks so the chunk sequence is a palindrome, and report the maximum number of chunks possible.
Level

Medium7 of 10

Topics
String, Greedy, Hash map, Prefix sum
Solved
No attempts yet

Problem

A partition of a string ss is a set of one or more non-overlapping non-empty substrings a1,a2,…,ada_1, a_2, \dots, a_d of ss whose concatenation is ss, that is s=a1+a2+⋯+ads = a_1 + a_2 + \dots + a_d. Each substring is called a chunk, and the length of the partition is the number of chunks dd.

A partition is written by putting every chunk in parentheses. For example, the string decode can be partitioned as (d)(ec)(ode), (d)(e)(c)(od)(e), (decod)(e), (decode), (de)(code), and in many other ways.

A partition is palindromic if the sequence of chunks reads the same forwards and backwards when each chunk counts as one atomic unit. The only palindromic partitions of decode are (de)(co)(de) and (decode). The second one shows that every word has a palindromic partition of length one.

Given a word ss, compute the largest possible length of a palindromic partition of ss.

Input

The first line contains the number of test cases tt. Each of the next tt lines holds one test case: a single word ss made of lowercase letters of the English alphabet. The input contains no spaces.

Output

For every test case print one line with the length of the longest palindromic partition of the word ss.

Constraints

Let nn be the length of the word ss.

  • 1≤t≤101 \le t \le 10
  • 1≤n≤1061 \le n \le 10^6

Examples1

  1. Example 1

    Input
    4
    bonobo
    deleted
    racecar
    racecars
    
    Expected output
    3
    5
    7
    1