Dobby's Case-Insensitive Word Test

Interview

Time limit1sMemory limit128 MB

Summary
For each test case, output the original-cased word that is smallest in dictionary order when comparisons ignore letter case.
Level

Easy2 of 10

Topics
String, Sorting, Implementation
Solved
No attempts yet

Problem

Koong shows Dobby several English words and says Dobby will be set free if he can identify the word that comes first in dictionary order when letter case is ignored.

To make the task harder, Koong mixes uppercase and lowercase letters freely. For example, apPle comes before Bat, but after AnT.

For each test case, find the word that is earliest in case-insensitive dictionary order, and print it exactly as it appeared in the input.

Input

The input consists of several test cases.

Each test case begins with an integer n, the number of words. Here, 2 <= n <= 1000.

Each of the next n lines contains one English word of length at most 20. Within one test case, no two words become the same after ignoring case.

The input ends with a single 0.

Output

For each test case, print the word that comes first in case-insensitive dictionary order, preserving its original capitalization.

Examples1

  1. Example 1

    Input
    3
    Cat
    fat
    bAt
    4
    call
    ball
    All
    Hall
    0
    
    Expected output
    bAt
    All