Last Name First, Please 

An administrative assistant is presented with the problem or renaming a group of files containing photos of employees. The files are currently named with the employee's first name first, i.e., the photo of John Smith is named John Smith.jpg. The names must be changed so that the last name appears first, i.e., Smith John.jpg.


The files are listed in a window in alphabetical order by file name, and are renamed by selecting them with a mouse or cursor keys, then typing the new name, followed by the enter key. Immediately after a file is renamed, the ordering of the files is updated in the window, and the file just renamed remains selected.


For example, the list may originally display (with the first name selected) as

After renaming the selected file, the appearance of the list changes to this:

To save keystrokes, the administrative assistant decides to choose a file adjacent to the selected one, either Nancy Schnell.jpg or Ruth Sandweiss.jpg, to rename next, thus requiring only a single cursor keystroke to select the next file. Note that after a few files are renamed, it may be the case that the selected file is adjacent only to already-renamed files, so that a single cursor keystroke is not sufficient to select another file to rename. The cursor key does not cause the selected file to "wrap around" from last to first name or vice.

Input 

The input file will contain a list of at most 20 file names, one per line, terminated with carriage returns. No file name will contain more than 32 characters. The first and last names will all be strings of letters, with only the first capitalized. You may assume that the ``last name" is that portion of the file name between the first space character and the period. In addition, you may assume that no two last names will be identical

Output 

If the files can be renamed, starting with the first file in the list, in such an order that only a single cursor keystroke is used between renamings, your output should be the file names, last names first, in the order they are renamed. If there is no such renaming, your output should be the phrase NO QUICK RENAMING POSSIBLE.

Sample Input 

Christina Peter.jpg
Ganesh Ramanarayanan.jpg
Laurie Yorr.jpg
Lucy Kraus.jpg
Melanie Ayala.jpg
Nancy Schnell.jpg
Ruth Sandweiss.jpg

Sample Output 

NO QUICK RENAMING POSSIBLE



Miguel A. Revilla
1999-01-11