Note = Struct.new(:id, :pitch, :octave, :duration, :volume) do
  def to_s # for debug
    "id:#{id} V#{volume} O#{octave} #{duration} #{pitch}"
  end
end

class Emulator
  attr_accessor :octave, :length, :volume, :score
  DEFAULT_OCTAVE = 4
  DEFAULT_LENGTH = 4
  DEFAULT_VOLUME = 100

  def initialize
    @octave = DEFAULT_OCTAVE
    @length = DEFAULT_LENGTH
    @volume = DEFAULT_VOLUME
    @score = []
  end

  def step(match_data)
    _, octave_shifter, command, number, dots = *match_data
    number = number.to_i

    if octave_shifter
      shift_octave(octave_shifter)
      return
    end

    case command
    when ?O
      @octave = number
    when ?L
      @length = number
    when ?V
      @volume = number
    when ?R
      duration = num_to_dur(number, dots)
      duration = tie(duration) if @score.last.pitch == ?R
      @score.push Note.new(@score.size, command, @octave, duration, @volume)
    else # ?A..?G
      number = @length if number == 0
      duration = [number, dots]
      pitch, octave = pitch_normalize(command)
      @score.push Note.new(@score.size, pitch, octave, duration, @volume)
    end
  end

  def shift_octave(shifter)
    @octave += shifter[?>] ? 1 : -1
  end

  def num_to_dur(num,dots)
    denom = num>0? num : @length
    (0..dots.size).map{|i|128/denom/2**i}.reduce :+
  end

  def tie(duration)
    @score.pop.duration + duration
  end

  def pitch_normalize(pitch)
    octave = @octave
    (pitch = ?C; octave += 1) if pitch == "B+"
    (pitch = ?B; octave -= 1) if pitch == "C-"
    [pitch, octave]
  end
end


def minimize_volume(score, sequence)
  score.each.with_index do |note,i|
    prev = i==0? Emulator::DEFAULT_VOLUME : score[i-1].volume
    current = note.volume

    sequence[note.id] << "V#{current}" unless current == prev
  end
end

def minimize_pitch(score, sequence)
  score.each.with_index do |note, i|
    prev_octave = i==0? Emulator::DEFAULT_OCTAVE : score[i-1].octave
    current = note

    if current.pitch == ?C && prev_octave - current.octave < 0
      next_note = score[i+1]
      if next_note && current.octave >= next_note.octave
        current.pitch = "B+"
        current.octave -= 1;
      end
    elsif current.pitch == ?B && prev_octave - current.octave > 0
      next_note = score[i+1]
      if next_note && current.octave <= next_note.octave
        current.pitch = "C-"
        current.octave += 1;
      end
    end

    diff = prev_octave - current.octave
    if diff != 0
      if diff.abs == 1
        sequence[note.id] << (diff == 1 ? ?< : ?>)
      else
        sequence[note.id] << "O#{current.octave}"
      end
    end

    sequence[note.id] << note.pitch
  end
end

def minimize_length(score, sequence)
  n = score.size
  numbers = Array.new(n)
  dots = Array.new(n){""}

  score.each.with_index do |note,i|
    current = note.duration

    if note.pitch == ?R
      # 各音符ごとに分割
      length_list = [current/128]+(0..6).map{|i|current[i]}.reverse

      # 全音符以上を処理
      numbers[i] = []
      dots[i] = []
      (length_list[0] - 1).times{numbers[i] << 1; dots[i] << ""}
      length_list[0] = 1 unless length_list[0] == 0

      # 各音符をR2.R16.のように表す
      length_list.unshift(0).push(0)
      length_list.each_cons(2).with_index do |v,j|
        if v == [0,1]
          $val = ""
          numbers[i] << 2**j
        elsif v == [1,1]
          $val << ?.
        elsif v == [1,0]
          dots[i] << $val
        end
      end      
    else
      numbers[i] = current[0]
      dots[i] = current[1]
    end
  end

  n.times do |i|
    if numbers[i].is_a?(Array)
      if numbers[i].size == 1
        # Rが一つで表せるならまんま
        numbers[i] = numbers[i][0]
        dots[i] = dots[i][0]
      else
        # Rが二つ以上なら順を考慮
        # とりあえず隣だけ見る 不完全かも
        length_list = numbers[i].zip(dots[i])
        length_list.sort_by!{|v|v[0]}
        prev_l = numbers[i-1] # 隣は確実に休符でない
        next_l = numbers[i+1]
        if l_index = length_list.index{|v|v[0]==prev_l}
          r_index = length_list.rindex{|v|v[0]==prev_l}
          pre = length_list.slice!(l_index..r_index)
          length_list.unshift(*pre)
        end
        if l_index = length_list.index{|v|v[0]==next_l}
          r_index = length_list.rindex{|v|v[0]==next_l}
          post = length_list.slice!(l_index..r_index)
          length_list.push(*post)
        end
        length_list = length_list.transpose
        numbers[i] = length_list[0]
        dots[i] = length_list[1]
      end
    end
  end

  # いい感じに展開して
  chains = []
  count = 0
  prev = nil
  numbers.flatten.each.with_index do |num,i|
    if num != prev
      digit = num.to_s.size
      count = 1
      chains << [num,digit,count]
    else
      count += 1
      chains.last[2] = count
    end
    prev = num
  end
  chains.each do |chain|
    chain.push(*[1 + chain[1], chain[1] * chain[2]])
  end

  # 全体で省略を考えて
  defo = Emulator::DEFAULT_LENGTH
  iterator = 0
  while iterator < chains.size
    chain = chains[iterator]
    pre = chain[3] # Ln
    post = chain[4] # XnXnXn

    if chain[0] == defo
      chain << :omit
    elsif pre < post
      chain << :pre
      defo = chain[0]
    else
      chain << :post
    end

    nextnext_c = chains[iterator+2]
    if nextnext_c && chain[0] == nextnext_c[0] # 先に同じのがあったら特殊処理 # もっとちゃんと見る
      next_c = chains[iterator+1]
      if next_c[3] - next_c[4] - nextnext_c[4] > 0
        next_c << :pre
        defo = next_c[0]
        iterator += 1
      else
        (chain[5] = :pre
        defo = chain[0]) if chain[5] == :post
        next_c << :post
        iterator += 1
        nextnext_c << :omit
        iterator += 1
      end
    end

    iterator += 1
  end

  # chain形式からnotation形式に
  flat_notation = chains.flat_map do |chain|
    if chain[5] == :pre
      [:pre] + [:omit] * (chain[2] - 1)
    else
      [chain[5]] * chain[2]
    end
  end
  iterator = 0
  notation = numbers.map do |v|
    if v.is_a?(Array)
      size = v.size
      ret = flat_notation[iterator,size]
      iterator += size
    else
      ret = flat_notation[iterator]
      iterator += 1
    end
    ret
  end

  # p numbers, dots, chains, notation

  # 文字列にして
  numbers.each.with_index do |number,i|
    if number.is_a?(Array)
      sequence[i] = ""
      seque = ""
      number.each.with_index do |numb,j|
        num = numb.to_s
        seq = "R"
        case notation[i][j]
        when :pre
          seq = "L#{num}" + seq
        when :post
          seq << num
        end
        seq << dots[i][j]
        seque << seq
      end
      sequence[i] << seque
    else
      num = number.to_s
      case notation[i]
      when :pre
        sequence[i] = "L#{num}" + sequence[i]
      when :post
        sequence[i] << num
      end
      sequence[i] << dots[i]
    end
  end
end

def minimize(score)
  sequence = Array.new(score.size){""}
  minimize_volume(score.select{|note|note.pitch!=?R}, sequence)
  minimize_pitch(score.select{|note|note.pitch!=?R}, sequence)
  score.each{|note|sequence[note.id]<<note.pitch if note.pitch==?R}
  minimize_length(score, sequence)
  sequence
end

REGEXP = /([<>])|([A-GROLV][+-]?)([0-9]*)(\.*)/

while gets
  break if $_[?*]

  # read
  emulator = Emulator.new
  while $_ =~ REGEXP
    emulator.step $~
    $_ = $'
  end

  # minimize
  sequence = minimize(emulator.score)

  # write
  puts "Case #$.: #{sequence*""}"
  # puts emulator.score
end