#P16518. [GKS 2015 #E] Lazy Spelling Bee

[GKS 2015 #E] Lazy Spelling Bee

Problem Description

In the Lazy Spelling Bee, a contestant is given a target word WW to spell. The contestant's answer word AA is acceptable if it is the same length as the target word, and the ii-th letter of AA is either the ii-th, (i1)(i-1)th, or (i+1)(i+1)th letter of WW, for all ii in the range of the length of AA. (The first letter of AA must match either the first or second letter of WW, since the 0th letter of WW doesn't exist. Similarly, the last letter of AA must match either the last or next-to-last letter of WW.) Note that the target word itself is always an acceptable answer word.

You are preparing a Lazy Spelling Bee, and you have been asked to determine, for each target word, how many distinct acceptable answer words there are. Since this number may be very large, please output it modulo 10000000071000000007 (109+710^9 + 7).

Input Format

The first line of the input gives the number of test cases, TT. TT test cases follow; each consists of one line with a string consisting only of lowercase English letters (a through z).

Output Format

For each test case, output one line containing "Case #x: y", where xx is the test case number (starting from 1) and yy is the number of distinct acceptable answer words, modulo 109+710^9 + 7.

4
ag
aa
abcde
x
Case #1: 4
Case #2: 1
Case #3: 108
Case #4: 1

Hint

In sample case #1, the acceptable answer words are aa, ag, ga, and gg.

In sample case #2, the only acceptable answer word is aa.

Limits

1T1001 \le T \le 100.

Small dataset (Test Set 1 - Visible)

11 \le length of each string 5\le 5.

Large dataset (Test Set 2 - Hidden)

11 \le length of each string 1000\le 1000.