{"raw_statement":[{"iden":"statement","content":"Note: this is a harder version of Mirrored string I.\n\nThe gorillas have recently discovered that the image on the surface of the water is actually a reflection of themselves. So, the next thing for them to discover is mirrored strings.\n\nA mirrored string is a palindrome string that will not change if you view it on a mirror. \n\nExamples of mirrored strings are \"MOM\", \"IOI\" or \"HUH\". Therefore, mirrored strings must contain only mirrored letters {A, H, I, M, O, T, U, V, W, X, Y} and be a palindrome.\n\ne.g. IWWI, MHHM are mirrored strings, while IWIW, TFC are not.\n\nA palindrome is a string that is read the same forwards and backwards.\n\nGiven a string S of length N, help the gorillas by printing the length of the longest mirrored substring that can be made from string S.\n\nA substring is a (possibly empty) string of characters that is contained in another string S. e.g. \"Hell\" is a substring of \"Hello\".\n\nThe first line of input is T – the number of test cases.\n\nEach test case contains a non-empty string S of maximum length 1000. The string contains only uppercase English letters.\n\nFor each test case, output on a line a single integer - the length of the longest mirrored substring that can be made from string S.\n\n"},{"iden":"input","content":"The first line of input is T – the number of test cases.Each test case contains a non-empty string S of maximum length 1000. The string contains only uppercase English letters."},{"iden":"output","content":"For each test case, output on a line a single integer - the length of the longest mirrored substring that can be made from string S."}],"translated_statement":null,"sample_group":[],"show_order":[],"formal_statement":"**Definitions**  \nLet $ T \\in \\mathbb{Z} $ be the number of test cases.  \nLet $ \\mathcal{M} = \\{A, H, I, M, O, T, U, V, W, X, Y\\} $ be the set of mirrored characters.  \nFor each test case, let $ S $ be a string of length $ N $, where $ S \\in \\Sigma^* $ and $ \\Sigma = \\{A, B, \\dots, Z\\} $.\n\n**Constraints**  \n1. $ 1 \\le T \\le \\text{unknown (implied by input)} $  \n2. For each string $ S $:  \n   - $ 1 \\le |S| \\le 1000 $  \n   - $ S $ contains only uppercase English letters.  \n\n**Objective**  \nFor each string $ S $, find the maximum length $ L $ such that there exists a substring $ S[i:j] $ (with $ 1 \\le i \\le j \\le |S| $) satisfying:  \n1. $ S[i:j] $ is a palindrome: $ S[i+k] = S[j-k] $ for all $ k = 0, 1, \\dots, \\left\\lfloor \\frac{j-i}{2} \\right\\rfloor $,  \n2. Every character in $ S[i:j] $ belongs to $ \\mathcal{M} $.  \n\nOutput $ L = \\max \\{ |S[i:j]| \\mid S[i:j] \\text{ is a mirrored substring} \\} $.","simple_statement":"Find the longest substring that is a palindrome and contains only mirrored letters: A, H, I, M, O, T, U, V, W, X, Y.","has_page_source":false}