Under construction

Still being built. Things may change

Acronyms

Interview

Time limit1sMemory limit256 MB

Summary
Given an acronym and candidate phrases, print the phrases whose word initials match the acronym letters in order.
Level

Easy1 of 10

Topics
String, Implementation
Solved
No attempts yet

Problem

Many acronyms are spelled with the same letters but mean different things. ISS can mean International Space Station, In School Suspension, or Interstate Sporadic Squabbles. It cannot mean Institutional Saliva Tester, which shortens to IST, and it cannot mean Intermural Sports Situational Comedies, which shortens to ISSC.

A phrase fits an acronym when it has exactly as many words as the acronym has letters, and the first letter of each word is the letter at the same position in the acronym. Every word begins with a capital letter.

Given an acronym and a list of candidate phrases, find the phrases that fit the acronym.

Input

The first line contains the number of data sets, which is at most 10.

The first line of each data set contains the acronym and the number of candidate phrases, separated by a space. The number of candidate phrases is at most 10. Each of the following lines contains one candidate phrase.

Output

For each data set, print the acronym on its own line, then print every phrase that fits the acronym, one per line, in the order the phrases were given. If no phrase fits, print only the acronym.

Examples2

  1. Example 1

    Input
    4
    ABC 4
    American Broadcasting Company
    Another Boring Computer Program
    Alpha Beta Gamma
    Another Brilliant Csteacher
    UIL 3
    Union Leaders Invitation
    University Interscholastic League
    Upstanding Important Leaders
    CIA 4
    Central Intelligence Agency
    Computer Image Advertising
    Coming In After Christmas
    Clubbing Intelligent Aardvarks
    TBBT 7
    The Big Bang Theory
    The Big Bama Tide
    Two Boolean Byte TreeMaps
    Thing Without An Important Name
    Tuning Big Brass Tubas
    This Bytes Big Boogies Totally
    Disk Operating System
    
    Expected output
    ABC
    American Broadcasting Company
    Another Brilliant Csteacher
    UIL
    University Interscholastic League
    Upstanding Important Leaders
    CIA
    Central Intelligence Agency
    Computer Image Advertising
    Clubbing Intelligent Aardvarks
    TBBT
    The Big Bang Theory
    The Big Bama Tide
    Two Boolean Byte TreeMaps
    Tuning Big Brass Tubas
    
  2. Example 2

    Input
    2
    A 3
    Apple
    Banana
    Awesome Aardvark
    Z 1
    Zebra
    
    Expected output
    A
    Apple
    Z
    Zebra