def decode(str)
  res = []
  if str.count('_') > 0
    res = str.split('_')
  else
    if /[a-z]/.match(str[0])
      str[0] = str[0].upcase
    end
    str.chars.each do |c|
      if /[A-Z]/.match(c)
        res << c.downcase
      else
        res[-1] << c.downcase
      end
    end
  end
  return res
end

def encode(vs, t)
  res = ""
  if t == 'D'
    res = vs * '_'
  else
    vs.each do |str|
      str[0] = str[0].upcase
      res << str
    end
    if t == 'L'
      res[0] = res[0].downcase
    end
  end
  return res
end

while true
  str, t = gets.split
  break if t == 'X'
  puts(encode(decode(str), t))
end
