TONES - Tone Transposition

Nalin really loves music, just like her father. When she was a child, she got keyboard classes at a private school. After she got married, she decided to play and sing a music for her husband at the piano. She searched for the song Endless Love over the internet to learn how to play it, but, unfortunately, the tone wasn't good enough for her to sing. If it was a keyboard, she could just hit a button and the problem would be solved, but there's no such button in a piano. She began to make the tone transposition with a paper and a pen, but it was taking too long, then she asked her husband to write her a program to do it, without telling him what was it for.

If you want to know a little bit more about tone transposition, in order to solve the problem, please read the end of problem statement.

Input
In each test cases, first line is n<=1000 and in the next line, a number t, -12<=t<=+12. In the third, and last, line of each case, n chords follow. All chords, whose size does not exceed 15 characters, are valid chords from music theory such as CMajor, F#Major, D#Maj7, A#b5, G7(b5)(b9), etc., and they are composed of letters, numbers and the following symbols "(", ")", "#", "-". There's no flat for chords in the input (Bb for example is represented as A#) and also there's no bass inversion, such as G4/B.

The end of input is when n=0.

Output
The sequence of n chords transposed by t semitones, one per line.

Score
Source length.

Input:
7
-3
C D E F G A B
8
+2
C Am Dm G C Am Dm G
4
+4
F#m D A E
5
+2
Gmaj7 D D#dim7 Em7 C9
0

Output:
A B C# D E F# G#
D Bm Em A D Bm Em A
A#m F# C# G#
Amaj7 E Fdim7 F#m7 D9


The sequences of chords is: C C# D D# E F F# G G# A A# B. Perform a tone transposition by t semitones is just shifting a note through the list above. For example: if you have C and want to transpose it by +2, it goes to D. If it has a suffix, you just keep the suffix like: Cm7 by +2 goes to Dm7. If you transpose B by +1, it goes to C. If t is negative, you just have to go backwards.


Added by:campos20
Date:2014-01-04
Time limit:10s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ASM64 GOSU
Resource:Music theory.

hide comments
2016-12-27 14:05:41
In the last testcase of the example, n, the number of chords, is six. Yet there are only five chords listed.

Alexandre: Fixed, thanks!

Last edit: 2019-02-11 19:39:50
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.