P15561 [CCPC 2025 Harbin Site] The Judge of Gensokyo

Description

:::align{center} ![](https://cdn.luogu.com.cn/upload/image_hosting/ngdf7srn.png) Image source: Bad Apple!! PV【影絵】 ::: Shiki is a judge in Gensokyo and often needs to write down a lot of text with pen and paper. Shiki found that many English letters, such as $\texttt{ovw}$, will form ligatures when written. For example, two consecutive handwritten $\texttt{v}$ connected together look like $\texttt{w}$; consecutive $\texttt{v}$ and $\texttt{w}$ will also connect together. For example, $\texttt{wvvwvwv}$ looks like a chain of $\texttt{v}$ with length $10$. Shiki thinks a string is good if and only if, when written on paper, it is a perfect mirror image. For example, $\texttt{wvowv}$ is mirrored, because when written it is three sharp corners, one circle, and three sharp corners; while $\texttt{vowow}$ is not symmetric, because on its leftmost side there are two sharp corners, but on the right side there are three. Now Shiki gives you a string $s$ that she recorded, and it is guaranteed that $s$ only consists of $\texttt{ovw}$. You need to find a longest substring of $s$ such that this substring is good.

Input Format

The first line contains an integer $T$, the number of test cases. Then for each test case: The first line contains an integer $n$ ($1 \le n \le 10^7$), the length of the string $s$. The second line contains a string $s$ of length $n$, guaranteed to consist only of $\texttt{ovw}$. It is guaranteed that $\sum n\le 10^7$ over all test cases.

Output Format

For each test case, output one line containing a string, representing a longest good substring of $s$. If there are multiple answers, you may output any one of them.

Explanation/Hint

Translated by ChatGPT 5