#P12672. 「LAOI-8」近期我们注意到有网站混淆视听

    ID: 11633 远端评测题 1000ms 512MiB 尝试: 0 已通过: 0 难度: 1 上传者: 标签>字符串洛谷原创O2优化洛谷月赛

「LAOI-8」近期我们注意到有网站混淆视听

Description

As a law-abiding Luogu user, we support only authentic contests.

You are given TT contest names (strings containing only letters and digits), which may not follow standard naming conventions. You can perform a swap between any two characters per operation. Your goal is to eliminate any case where both substrings LGR and CSP coexist in the same string.

For example, LGRCSP can be transformed in one move to LGRSCP.

Output the minimum number of operations required to eliminate this conflict.

Input Format

The first line contains a single integer TT, the number of test cases.

Each of the next TT lines contains one string ss, the contest name.

Output Format

For each test case, output a single integer — the minimum number of swaps required.

3
LGR201Div3CSP2024dierlunmoni
QAQ
LGRLGR114514Div2CSPCSP2025dierlunmoni
1
0
1

Hint

Subtasks are used in this problem.

Let tt be the length of string ss.

Subtask tt Score
11 103\le 10^3 4040
22 105\le 10^5 6060

For all test cases, it is guaranteed that 1T101\le T \le 10, 1t1051 \le t \le 10^5.