#614
Bronze II
Moo Operations
시간 제한
2s
메모리 제한
1024MB
제출
0
정답
0
맞힌 사람
0
정답 비율
0.0%

문제

Because Bessie is bored of playing with her usual text string where the only characters are 'C,' 'O,' and 'W,' Farmer John gave her QQ new strings (1Q1001 \leq Q \leq 100), where the only characters are 'M' and 'O.' Bessie's favorite word out of the characters 'M' and 'O' is obviously "MOO," so she wants to turn each of the QQ strings into "MOO" using the following operations:

Replace either the first or last character with its opposite (so that 'M' becomes 'O' and 'O' becomes 'M'). Delete either the first or last character.

Unfortunately, Bessie is lazy and does not want to perform more operations than absolutely necessary. For each string, please help her determine the minimum number of operations necessary to form "MOO" or output 1-1 if this is impossible.

입력

The first line of input contains the value of QQ.

The next QQ lines of input each consist of a string, each of its characters either 'M' or 'O'. Each string has at least 1 and at most 100 characters.

출력

Output the answer for each input string on a separate line.

예제 입력 1

3
MOMMOM
MMO
MOO

예제 출력 1

4
-1
0

점수

Inputs 2-4: Every string has length at most 33.Inputs 5-11: No additional constraints.

코드 제출

코드를 제출하려면 로그인이 필요합니다.

로그인
내 제출
제출 내역이 없습니다.
맞은 사람
아직 맞은 사람이 없습니다.
난이도 투표
Bronze II1명 투표· 약 1개월 전
로그인 후 AC 받으면 투표할 수 있습니다.
전체 제출
제출 내역이 없습니다.