D2. Prefix-Suffix Palindrome (Hard version)
time limit per test :2 seconds memory limit per test :256 megabytes
input :standard input output :standard output
This is the hard version of the problem. The difference is the constraint on the sum of lengths of strings and the number of test cases. You can make hacks only if you solve all versions of this task.
You are given a string s, consisting of lowercase English letters. Find the longest string, t, which satisfies the following conditions:
- The length of t does not exceed the length of s.
- tt is a palindrome.
- There exists two strings a and b (possibly empty), such that t=a+b ( "+" represents concatenation), and a is prefix of s while b is suffix of s.
Input
The input consists of multiple test cases. The first line contains a single integer t (), the number of test cases. The next t lines each describe a test case.
Each test case is a non-empty string s, consisting of lowercase