Under construction

Still being built. Things may change

Music Collection (Small1)

Time limit5sMemory limit512 MB

Summary
For each song, find the shortest substring that appears in that song and in no other song, breaking ties by a custom lexicographic order.
Level

Medium4 of 10

Topics
String matching, Brute force
Solved
No attempts yet

Problem

Phil has a huge music collection and he is picky about what he listens to. Each song has a name that is a string of characters. His music player has a search box: type a string into it and the player lists every song whose name contains that string. When exactly one song matches, Phil presses Enter and that song plays.

Phil hates using the mouse and he hates typing, so for the song he wants right now he always types the shortest string that matches that one song and nothing else. Find that query for every song.

Input

The first line contains the number of test cases TT. Each test case starts with a line holding the number of songs NN, followed by NN lines with one song name each. These NN names are Phil's whole collection.

A song name consists of letters, spaces and the hyphen character (-), and its length is between 1 and 100. Within one test case all song names are different. Names and the search are case insensitive, so "dZihan" and "Dzihan" are the same name.

Limits

  • 1≤T≤1001 \le T \le 100
  • 1≤N≤101 \le N \le 10

Output

For each test case print one line "Case #xx:", where xx is the test case number starting from 1. Then print one line per song, in the order the songs were given. For each song print, wrapped in double quotes, the shortest query that matches that song and no other song. If several shortest queries work, print the lexicographically smallest one. If no query works, print :( without quotes.

A query is a string of letters, spaces and hyphens, and the empty string is a valid query. The empty string is contained in every name.

In the lexicographic order a space comes before a hyphen, a hyphen comes before every letter, and upper case letters come before lower case letters.

Examples2

  1. Example 1

    Input
    5
    6
    A Perfect Circle - Gravity
    Aimee Mann - You Do
    Aqualung - Cinderella
    Arcade Fire - Haiti
    Art of Noise - Pleure
    ATB - Marrakech
    2
    Hybrid - Altitude
    Kings of Convenience - The Build-up
    3
    aaaaaaaabb
    aaaaaaabbb
    ababababab
    3
    butter
    fly
    butterfly
    1
    Unknown Artist - Track One
    
    Expected output
    Case #1:
    "V"
    " D"
    "Q"
    " F"
    "S"
    "B"
    Case #2:
    "A"
    "C"
    Case #3:
    "AAAAAAAA"
    "BBB"
    "BA"
    Case #4:
    :(
    :(
    "RF"
    Case #5:
    ""
    
  2. Example 2

    Input
    3
    2
    a b
    a-b
    1
    x
    2
    Ab
    aB
    
    Expected output
    Case #1:
    " "
    "-"
    Case #2:
    ""
    Case #3:
    :(
    :(