This page is still under construction.

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

Wildcard (Large)

Time limit5sMemory limit512 MB

Summary
Given two filenames A and B, find the shortest star pattern that matches A but not B, breaking ties by fewer stars then lexicographic order.
Level

Hard8 of 10

Topics
Dynamic programming, String matching, BFS
Solved
No attempts yet

Problem

Many operating systems let you use * (an asterisk) as a wildcard when you name a file. A * matches any string, and the empty string counts.

Wildcards are often used to name several files at once, and they also make naming a single file easier. Suppose you want to name the file pascalisamazing. If it is the only file matching the pattern pascal*, then that pattern names pascalisamazing, and pascal* is much shorter to type.

Given two file names, find the shortest pattern that matches the first name but not the second.

A pattern is a string of lowercase letters and *. The pattern matches a name if you can replace each * in it with some string, possibly the empty string, and get exactly that name.

Input

The first line has the number of test cases TT. Each test case takes two lines: the first file name AA on one line and the second file name BB on the next. File names consist of lowercase letters only.

Constraints

  • 1≤T≤1001 \le T \le 100
  • AA and BB are different strings
  • AA and BB are each 1 to 50 characters long

Output

For each test case print one line in this format.

Case #X: Y

XX is the test case number and YY is the shortest pattern that matches AA but not BB. If several patterns share the shortest length, print the one with the fewest asterisks. If several still remain, print the smallest one in lexicographic order. Compare characters by their ASCII codes, where the code 42 of * is smaller than any lowercase letter.

Examples2

  1. Example 1

    Input
    3
    a
    b
    abaa
    aaaa
    aaabaaaabaaa
    aaabaaabaaa
    
    Expected output
    Case #1: a
    Case #2: ab*
    Case #3: *aaaa*
    
  2. Example 2

    Input
    5
    a
    ab
    ab
    abc
    abc
    ab
    ab
    ba
    xy
    xz
    
    Expected output
    Case #1: a
    Case #2: ab
    Case #3: *c
    Case #4: ab
    Case #5: xy