class Q1044
  CONS = ?a - ?A
  def change name,type
    names = divStr name
    len = names.length
    ans = ""
    #cons = ?a - ?A
    if(type == "U")
      for i in 0..len-1
        names[i][0] = (names[i][0] - CONS).chr
        ans += names[i]
      end
    elsif(type == "L")
        ans += names[0]
      for i in 1..len-1
        names[i][0] = (names[i][0] - CONS).chr
        ans += names[i]
      end
    else
      ans += names[0]
      for i in 1..len-1
        ans += "_" + names[i]
      end
    end
    puts ans
  end
  def divStr str
    ary = Array.new
    tmp = ""
    len = str.length
    i = 0
    while(i < len)
      c = str[i]
      if(c == ?_)
        ary.push tmp
        tmp = ""
      elsif(?A <= c && c <= ?Z)
        if(tmp != "")
          ary.push tmp
        end
        tmp = ""
        tmp += (c + CONS).chr
      else
        tmp += c.chr
      end
      i += 1
      #puts tmp
=begin
      print "tmp = "
      puts tmp
      print "ary = "
      puts ary
=end
    end
    ary.push tmp
    return ary
  end
  
  def doIt
    s = gets.split " "
    while(s[1] != "X")
      change s[0],s[1]
      s = gets.split " "
    end
  end
end

Q1044.new.doIt