Under construction

Still being built. Things may change

Typewriter Monkey (Small)

Time limit5sMemory limit512 MB

Summary
Find the expected leftover bananas, which is the maximum achievable count of the target word minus its expected count in a random length S string.
Level

Medium5 of 10

Topics
Probability, Brute force, String matching
Solved
No attempts yet

Problem

A publishing house decided to produce literature by letting a monkey hit keys at random. The monkey's keyboard has KK keys, and each key is labeled with one uppercase English letter. Several keys can carry the same letter.

The monkey starts with an empty string and repeats the following SS times: it picks one key uniformly at random, presses it, and appends that key's letter to the right end of the string. The final string therefore has length SS.

You have a target word of length LL. It does not have to be a real English word. The target word can appear several times in what the monkey types, and overlapping occurrences are counted separately. If the target word is ABA and the monkey types ABABA, the number of occurrences is 2.

You pay the monkey one banana for each occurrence of the target word. When you go to inspect the work, you bring the smallest number of bananas that is always enough, no matter what the monkey typed. That is, you bring as many bananas as the largest number of occurrences that a length SS string typed on this keyboard can contain. Then you pay one banana per occurrence in the string the monkey actually typed, and you keep the rest.

Find the expected number of bananas you get to keep.

Input

The first line contains the number of test cases TT. Each test case consists of three lines. The first line contains the integers KK, LL, and SS, separated by spaces. The second line contains a string of KK uppercase English letters describing the monkey's keyboard. The third line contains a string of LL uppercase English letters describing the target word.

Limits

  • 1≤T≤1001 \le T \le 100
  • 1≤K≤71 \le K \le 7
  • 1≤L≤S≤71 \le L \le S \le 7

Output

For each test case, print one line in the form Case #x: y, where xx is the test case number starting from 1 and yy is the expected number of bananas you get to keep. Print yy rounded to six digits after the decimal point, with all six digits shown. Under these limits the answer never lands exactly on a rounding tie.

Examples1

  1. Example 1

    Input
    4
    7 6 6
    BANANAS
    MONKEY
    2 3 4
    AA
    AAA
    2 1 2
    AB
    B
    6 2 2
    GOOGLE
    GO
    
    Expected output
    Case #1: 0.000000
    Case #2: 0.000000
    Case #3: 1.000000
    Case #4: 0.888889