406756: GYM102535 M Kim Possible and the Mooks and the Reversinator

Memory Limit:800 MB Time Limit:6 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

M. Kim Possible and the Mooks and the Reversinatortime limit per test6 secondsmemory limit per test800 megabytesinputstandard inputoutputstandard output

Kim Possible has infiltrated Dr. Drakken's lair for the third time and has to fight off some MOOKS and MEEKS in order to stop him from his evil schemes.

Like both previous times, Dr. Drakken knew Team Possible was coming for him as they always have. So he prepared a magical scientific device to strengthen his army of MOOKS and MEEKS.

All the MOOKS and MEEKS form a straight line and Kim Possible has to fight them starting from the first one. The MEEKS don't fight because they are tired, but the MOOKS take Kim one minute to defeat. Whenever Kim Possible defeats a MOOK, the MOOK will use his McGuffin which drains all of his energy and throws Kim Possible back to the start of the line. All the MEEKS in front of the MOOK get re-energized and turn back into MOOKS with their McGuffin fully recharged, but the MOOK that used his McGuffin turns into a MEEK, fully drained of energy.

This time however, the scientific genius Wade provided Kim Possible with a new device called the Reversinator. The Reversinator can reverse the order of a section of the line, but it can only be used once. To be precise, when the reversinator is used to reverse the section from the $$$i$$$th opponent to the $$$j$$$th opponent, $$$i$$$ and $$$j$$$ swap positions, $$$i+1$$$ and $$$j-1$$$ swap positions, and so on.

Given the initial line of MOOKS and MEEKS and the optimal use of the Reversinator, how many minutes will it take for Kim Possible to defeat all the MOOKS and turn them into MEEKS, assuming the Reversinator is used exactly once before Kim starts fighting?

Since the answer may be very large, output the answer mod $$$10^9$$$.

Input

The first line of input contains $$$t$$$, the number of test cases.

Each test case consists of a single line containing a string $$$s$$$ consisting of the letters E and O. The $$$i$$$th character of $$$s$$$ is:

  • E if the $$$i$$$th opponent is a MEEK
  • O if the $$$i$$$th opponent is a MOOK

Constraints

We denote the length of $$$s$$$ by $$$|s|$$$.

  • $$$1 \le t \le 35000$$$
  • $$$1 \le |s| \le 5\cdot 10^5$$$.
  • The sum of the $$$|s|$$$ across all test cases in a single file is $$$\le 5\cdot 10^5$$$.
Output

For each test case, output a single line containing a single integer denoting the answer for that test case modulo $$$10^9$$$.

ExampleInput
1
EOOE
Output
3

加入题单

上一题 下一题 算法标签: