This page is still under construction.

Parts of this page are still being built. What you see may change.

Welcome to Code Jam (Small)

Interview

Time limit5sMemory limit512 MB

Summary
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.
Level

Medium4 of 10

Topics
Dynamic programming, String
Solved
No attempts yet

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

  • 1≤N≤1001 \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.

Examples3

  1. Example 1

    Input
    3
    elcomew elcome to code jam
    wweellccoommee to code qps jam
    welcome to codejam
    
    Expected output
    Case #1: 0001
    Case #2: 0256
    Case #3: 0000
    
  2. Example 2

    Input
    1
    welcome to code jam
    
    Expected output
    Case #1: 0001
    
  3. Example 3

    Input
    1
    maj edoc ot emoclew
    
    Expected output
    Case #1: 0000