logo AlgoBeat OnlineJudge
登录 注册

#213581. [GCJ 2008 Qualification] Saving the Universe

内存限制:1024 MiB 时间限制:3000 ms 标准输入输出
题目类型:VJudge(洛谷) 评测方式:VJudge
上传者: 匿名

题目描述

The urban legend goes that if you go to the Google homepage and search for "Google", the universe will implode. We have a secret to share... It is true! Please don't try it, or tell anyone. All right, maybe not. We are just kidding.

The same is not true for a universe far far away. In that universe, if you search on any search engine for that search engine's name, the universe does implode!

To combat this, people came up with an interesting solution. All queries are pooled together. They are passed to a central system that decides which query goes to which search engine. The central system sends a series of queries to one search engine, and can switch to another at any time. Queries must be processed in the order they're received. The central system must never send a query to a search engine whose name matches the query. In order to reduce costs, the number of switches should be minimized.

Your task is to tell us how many times the central system will have to switch between search engines, assuming that we program it optimally.

输入格式

The first line of the input file contains the number of cases, . test cases follow.

Each case starts with the number -- the number of search engines. The next lines each contain the name of a search engine. Each search engine name is no more than one hundred characters long and contains only uppercase letters, lowercase letters, spaces, and numbers. There will not be two search engines with the same name.

The following line contains a number -- the number of incoming queries. The next lines will each contain a query. Each query will be the name of a search engine in the case.

输出格式

For each input case, you should output:

Case #:

where is the number of the test case and is the number of search engine switches. Do not count the initial choice of a search engine as a switch.

样例

样例输入 1

2
5
Yeehaw
NSM
Dont Ask
B9
Googol
10
Yeehaw
Yeehaw
Googol
B9
Googol
NSM
B9
NSM
Dont Ask
Googol
5
Yeehaw
NSM
Dont Ask
B9
Googol
7
Googol
Dont Ask
NSM
NSM
Yeehaw
Yeehaw
Googol

样例输出 1

Case #1: 1
Case #2: 0

数据范围与提示

Sample Explanation

In the first case, one possible solution is to start by using Dont Ask, and switch to NSM after query number 8.

For the second case, you can use B9, and not need to make any switches.

Limits

Small dataset (5 Pts, Test set 1 - Visible)

Large dataset (20 Pts, Test set 2 - Hidden)