## ECOO '20 P1 - Music with Mimi

View as PDF

Points: 3 (partial)
Time limit: 20.0s
Memory limit: 256M

Author:
Problem type
Allowed languages
Ada, Assembly, Awk, Brain****, C, C#, C++, COBOL, CommonLisp, D, Dart, F#, Forth, Fortran, Go, Groovy, Haskell, Intercal, Java, JS, Kotlin, Lisp, Lua, Nim, ObjC, OCaml, Octave, Pascal, Perl, PHP, Pike, Prolog, Python, Racket, Ruby, Rust, Scala, Scheme, Sed, Swift, TCL, Text, Turing, VB, Zig

Mimi is learning music theory! Today, her teacher is covering dominant seventh chords. In Western music theory, the notes are as follows:

C C# D D# E F F# G G# A A# B C

Note that this list is cyclic.

Two consecutive notes form a semitone.

A dominant seventh chord in root position is a collection of 4 notes such that:

• the first and second notes form a major third (they are 4 semitones apart),
• the second and third notes form a minor third (they are 3 semitones apart), and
• the third and fourth notes also form a minor third.

For example, the chord G B D F is a dominant seventh chord in root position.

Finally, Mimi's teacher touches on the idea of inversions:

• The first inversion of G B D F is B D F G(cyclic shift by 1 to the left).
• The second inversion of G B D F is D F G B(cyclic shift by 2 to the left).
• The third inversion of G B D F is F G B D(cyclic shift by 3 to the left).

(Note in each case the notes loop around.)

Having finished class, Mimi's teacher assigns her homework: checking if a chord is a dominant seventh chord, and whether it is in root position, first inversion, second inversion, or third inversion.

#### Input Specification

The first line begins with a single integer  , the number of test cases. test cases follow. Each test case will contain one line: a chord composed of 4 notes.

For the first three cases, all valid dominant seventh chords will be in the root position.

For the first five cases, all valid dominant seventh chords will be either in the root position, or a first inversion.

#### Output Specification

For each test case, print either root if the chord is in root position, first if the chord is a first inversion, second if the chord is a second inversion, third if the chord is a third inversion, or invalid if the chord is not a dominant seventh.

#### Sample Input

3
G B D F
G A B C
B D F G

#### Sample Output

root
invalid
first

Note: you do NOT need to pass the sample to pass some of the cases.

Educational Computing Organization of Ontario - statements, test data and other materials can be found at ecoocs.org