This page is still under construction.

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

Counting welcome to code jam subsequences

Time limit5sMemory limit512 MB

Summary
Count subsequences of each input text that spell the 19-character target string, printed as the last four digits.
Level

Medium5 of 10

Topics
Dynamic programming, String
Solved
No attempts yet

Problem

Count how many times the 19 character string welcome to code jam appears as a subsequence of a given text.

To be precise, let tt be the text and consider an index sequence ss with s[0]<s[1]<⋯<s[18]s[0] < s[1] < \cdots < s[18]. Count the sequences ss for which concatenating t[s[0]]t[s[0]], t[s[1]]t[s[1]], ..., t[s[18]]t[s[18]] in that order gives exactly welcome to code jam. Two sequences that pick the same letters from different positions count separately.

The answer can be huge, so print 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 as a single line of text. Every line consists of lowercase English letters and spaces only, and never starts or ends with a space.

  • 1≤N≤1001 \le N \le 100
  • Each line is between 1 and 500 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 dddddddd is the last four digits of the answer. If the answer has fewer than four digits, pad it with leading zeros so that exactly four digits are printed.

Examples4

  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
    w
    
    Expected output
    Case #1: 0000
    
  4. Example 4

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