Under construction

Still being built. Things may change

File Fix-it (Large)

Interview

Time limit5sMemory limit512 MB

Summary
Count the directories along each wanted path that do not exist yet and report how many mkdir calls they need.
Level

Easy3 of 10

Topics
Trie, String
Solved
No attempts yet

Problem

A Unix computer stores data in directories. There is one root directory, and it can contain several directories with different names. Those directories can contain more directories, and so on.

A directory is identified by its name together with its parent directory, the directory it sits directly inside. This is usually written as a path made of several parts, each preceded by one forward slash ('/'). The last part is the name of the directory, and everything before it gives the path of the parent directory. Consider this path:

/home/gcj/finals

It refers to the directory named "finals" inside the directory described by "/home/gcj", which in turn refers to the directory named "gcj" inside the directory described by "/home". The path "/home" has only one part, so it refers to the directory named "home" in the root directory.

To create a directory you use the mkdir command. You give it a path, and mkdir creates the directory that path describes, but only if the parent directory already exists. For example, creating "/home/gcj/finals" and "/home/gcj/quals" from scratch takes four commands:

mkdir /home
mkdir /home/gcj
mkdir /home/gcj/finals
mkdir /home/gcj/quals

Given every directory that already exists on your computer and a list of directories you want to create, count how many mkdir commands you need to create the ones that are not there yet.

Input

The first line of the input gives the number of test cases, TT. TT test cases follow. Each case begins with a line containing two integers NN and MM, separated by one space.

The next NN lines each give the path of one directory that already exists on your computer. This list contains every directory already on your computer except the root directory. The root directory is on every computer, so it is never listed.

The next MM lines each give the path of one directory that you want to create.

Every path in the input follows the format described above. A path consists of one or more lower-case alphanumeric strings (characters 'a' to 'z' and '0' to '9'), each preceded by a single forward slash. These strings are never empty.

Limits

  • 1≤T≤1001 \le T \le 100
  • No path is longer than 100 characters.
  • No path appears twice in the list of directories already on your computer, and no path appears twice in the list of directories you want to create. The same path may appear once in each of the two lists.
  • If a directory is listed as already being on your computer, its parent directory is listed too, unless the parent is the root directory.
  • The whole input is at most 100,000 bytes.
  • 0≤N≤1000 \le N \le 100
  • 1≤M≤1001 \le M \le 100

Output

For each test case, print one line in the form "Case #x: y", where x is the case number starting from 1 and y is the number of mkdir commands you need.

Examples1

  1. Example 1

    Input
    3
    0 2
    /home/gcj/finals
    /home/gcj/quals
    2 1
    /chicken
    /chicken/egg
    /chicken
    1 3
    /a
    /a/b
    /a/c
    /b/b
    
    Expected output
    Case #1: 4
    Case #2: 0
    Case #3: 4