Campus Buildings

Interview

Time limit1sMemory limit128 MB

Summary
Given building names and an abbreviation, list the names whose letters contain the abbreviation as a case-insensitive subsequence, in input order.
Level

Easy3 of 10

Topics
String, Two pointers, Implementation
Solved
No attempts yet

Problem

Most campuses have many buildings with long official names, so schedules use abbreviations. Over time the abbreviations become so widely used that people barely remember the full names — like SAL, PHE, or OHE. For a newcomer this is confusing, so let’s write a small program that works out which buildings an abbreviation could refer to.

You are given a list of building names and a building abbreviation such as SAL or FRSSC. The abbreviation matches a building name if every letter of the abbreviation appears in the name, in the same order, with each matched to a distinct position (no letter of the name used twice). For example, SAL matches "SALvatori", "Student Aerospace Laboratory", and "univerSity of southern cALifornia", but it does not match "angeles" because the letters appear in the wrong order. Matching is case-insensitive, so 'S' and 's' are treated as the same letter.

Input

The first line contains an integer K≥1K \ge 1, the number of data sets. It is followed by KK data sets of the following form.

The first line of a data set contains the number of buildings nn (1≤n≤1001 \le n \le 100). The next nn lines each contain one building name, made up only of uppercase and lowercase letters and spaces. The last line of the data set contains the building abbreviation on a line by itself.

Output

For each data set, first print a line "Data Set x:", where x is the data set number (starting from 1). Then print every building name that the abbreviation matches, each on its own line, in the same order in which they appeared in the input list.

Examples1

  1. Example 1

    Input
    2
    3
    studENt aeRoSpace laBoratory
    salVAtori
    angeles
    SAL
    2
    SaLvatori
    Science LibrarieS
    SSL
    
    Expected output
    Data Set 1:
    studENt aeRoSpace laBoratory
    salVAtori
    Data Set 2: