Welcome to Code Jam (Small)

Count how many ways the 19-character phrase "welcome to code jam" appears as a subsequence of the input line, and print the last four digits.

Medium4Dynamic programmingStringInterviewNo attempts yetTime limit5sMemory limit512 MB

Problem

Skim a long paragraph and you can build the phrase "welcome to code jam" out of it: find a 'w', then find an 'e' later on, then an 'l' after that, and so on. The same paragraph gives many different ways to do it, depending on which letters you pick.

Given one line of text, count how many ways "welcome to code jam" appears in it as a subsequence. Formally, let SS be the input string and let TT = "welcome to code jam". Count the index sequences ss with s[0]<s[1]<<s[18]s[0] < s[1] < \cdots < s[18] such that concatenating S[s[0]],S[s[1]],,S[s[18]]S[s[0]], S[s[1]], \ldots, S[s[18]] gives TT. The length of TT is 19 including its spaces, and each space of TT must also be matched by a space of the input.

The count can be huge, so report only its last four digits.

Input

The first line contains the number of test cases NN. Each of the next NN lines contains one test case, a single line of text made of lower-case English letters and spaces. No line starts with a space and no line ends with a space.

Limits

  • 1N1001 \le N \le 100
  • Each line is at most 30 characters long.

Output

For each test case, print one line in the form Case #x: dddd, where xx is the test case number starting from 1 and dddd is the last four digits of the answer. If the answer has fewer than four digits, pad it with leading zeros so that it is exactly four digits long.