Under construction

Still being built. Things may change

Old Gold

Memory limit1024 MB

Summary
Count the gold placements that match each road marking's nearest-gold condition and leave at least one nugget, modulo 1000000007.
Level

Medium5 of 10

Topics
Dynamic programming, String
Solved
No attempts yet

Problem

A long, long time ago (77 years) you were on a West-East road in Southeast Asia that is known to contain at least one gold nugget. You had a limited but reliable gold detector. After getting immensely rich from that gold, you tried every activity you could think of and got bored of all of them. While wandering around your huge mansion, you found some notes from that gold hunt.

The notes are a diagram of the road. For each kilometer of road, one of five markings is written:

  • <: the closest gold nugget is to the West.
  • =: the closest gold nuggets to the East and to the West are at the same distance, and there is no gold nugget at that position.
  • >: the closest gold nugget is to the East.
  • o: there is a gold nugget at that position.
  • .: nothing is known about that position.

Each of the kk unknown (.) positions may or may not contain a gold nugget, independently of the others. Count how many of the 2k2^k placements of gold agree with all the notes and leave at least one gold nugget on the road overall. The count can be very large, so output it modulo the prime 109+710^9+7 (10000000071000000007).

Input

The first line contains the number of test cases TT. Each of the next TT lines contains a string SS that describes one test case. The ii-th character of SS is the marking for the ii-th kilometer of road, from West to East, using the code above.

Output

For each test case, output one line in the form Case #x: y, where xx is the test case number starting from 1 and yy is the number of valid gold placements modulo 109+710^9+7 (10000000071000000007).

Constraints

  • 1≤T≤1001 \le T \le 100.
  • Each character of SS is one of < (less than), = (equals), > (greater than), o (lowercase o), or . (period).
  • SS has at least 1 character, and not all characters of SS are . (period).

Hint

In Sample Case #1, there are three valid placements, which result in the roads oo≤>o<, oo≤>oo, and o<≤>>o.

In Sample Case #2, there is no valid placement.

In Sample Case #3, the only valid placement results in the road o=o. A valid placement must always leave at least one gold nugget on the road.

In Sample Case #4, all 2172^{17} placements are valid. The placement that leaves every unknown (.) position empty is also valid, because the road still has one gold nugget in that placement.

Examples1

  1. Example 1

    Input
    4
    o..=>..
    ...o>..........
    .=.
    .........o........
    
    Expected output
    Case #1: 3
    Case #2: 0
    Case #3: 1
    Case #4: 131072