Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

func configure(scanner *bufio.Scanner) {
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1000005), 1000005)
}
func getNextString(scanner *bufio.Scanner) string {
	scanned := scanner.Scan()
	if !scanned {
		panic("scan failed")
	}
	return scanner.Text()
}
func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}
func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}
func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}
func main() {
	fp := os.Stdin
	wfp := os.Stdout
	extra := 0
	if os.Getenv("I") == "IronMan" {
		fp, _ = os.Open(os.Getenv("END_GAME"))
		extra = 100
	}
	scanner := bufio.NewScanner(fp)
	configure(scanner)
	writer := bufio.NewWriter(wfp)
	defer func() {
		r := recover()
		if r != nil {
			fmt.Fprintln(writer, r)
		}
		writer.Flush()
	}()
	solve(scanner, writer)
	for i := 0; i < extra; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
}
func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	for s, c := getNextString(scanner), getNextString(scanner); c != "X"; s, c = getNextString(scanner), getNextString(scanner) {
		if strings.Index(s, "_") != -1 {
			fmt.Fprintln(writer, translate(strings.Split(s, "_"), c))
			continue
		}
		ss := make([]string, 0)
		for len(s) > 0 {
			index := nextupper(s[1:])
			ss = append(ss, s[:index+1])
			s = s[index+1:]
		}
		fmt.Fprintln(writer, translate(ss, c))
	}
}
func translate(ss []string, c string) string {
	switch c {
	case "U":
		return u(ss)
	case "L":
		return l(ss)
	case "D":
		return d(ss)
	}
	return ""
}

func nextupper(s string) int {
	n := len(s)
	for i := 0; i < n; i++ {
		if s[i:i+1] == strings.ToUpper(s[i:i+1]) {
			return i
		}
	}
	return n
}
func u(ss []string) string {
	n := len(ss)
	for i := 0; i < n; i++ {
		ss[i] = fmt.Sprintf("%s%s", strings.ToUpper(ss[i][0:1]), ss[i][1:])
	}
	return strings.Join(ss, "")
}
func l(ss []string) string {
	n := len(ss)
	ss[0] = strings.ToLower(ss[0])
	for i := 1; i < n; i++ {
		ss[i] = fmt.Sprintf("%s%s", strings.ToUpper(ss[i][0:1]), ss[i][1:])
	}
	return strings.Join(ss, "")
}
func d(ss []string) string {
	n := len(ss)
	for i := 0; i < n; i++ {
		ss[i] = strings.ToLower(ss[i])
	}
	return strings.Join(ss, "_")
}

Python: while True:
    words, type_ = input().split()
    if type_ == "L":
        if "_" in words:
            words = words.split("_")
            words = words[0] + "".join([w[0].upper() + w[1:] for w in words[1:]])
        else:
            words = words[0].lower() + words[1:]
    elif type_ == "U":
        if "_" in words:
            words = words.split("_")
            words = "".join([w[0].upper() + w[1:] for w in words])
        else:
            words = words[0].upper() + words[1:]
    elif type_ == "D":
        indices = [i for i, w in enumerate(words) if w.isupper()] + [len(words)]
        if words[0].islower():
            indices.insert(0, 0)
        words = "_".join([words[indices[i]].lower() + words[indices[i]+1: indices[i+1]] for i in range(len(indices) - 1)])
    else:
        break
    print(words)

Python: while True:
    words, type_ = input().split()
    if type_ == "L":
        if "_" in words:
            words = words.split("_")
            words = words[0] + "".join([w[0].upper() + w[1:] for w in words[1:]])
        else:
            words = words[0].lower() + words[1:]
    elif type_ == "U":
        if "_" in words:
            words = words.split("_")
            words = "".join([w[0].upper() + w[1:] for w in words])
        else:
            words = words[0].upper() + words[1:]
    elif type_ == "D":
        indices = [i for i, w in enumerate(words) if w.isupper()] + [len(words)]
        if words[0].islower():
            indices.insert(0, 0)
        words = "_".join([words[indices[i]].lower() + words[indices[i]+1: indices[i+1]] for i in range(len(indices) - 1)])
    else:
        break
    print(words)

Python: import re
while True:
    c, t = input().split()
    if t == "X":
        break
    if t == "U":
        if "_" in c:
            tmp = c.split("_")
            hoge = ""
            for t in tmp:
                hoge += t[0].upper() + t[1:]
            c = hoge
        else:
            c = c[0].upper() + c[1:]
    elif t == "L":
        if "_" in c:
            tmp = c.split("_")
            flag = True if len(tmp) > 1 else False
            hoge = ""
            for t in tmp:
                hoge += t[0].upper() + t[1:]
            if flag:
                hoge = hoge[0].lower() + hoge[1:]
            c = hoge
        else:
            if re.match('[A-Z]', c):
                c = c[0].lower() + c[1:]
            else:
                c = c[0].upper() + c[1:]
    else:
        tmp = re.findall('[a-zA-Z][a-z]+', c)
        hoge = ""
        for t in tmp:
            hoge += t[0].lower() + t[1:] + "_"
        c = hoge[:-1]
    print(c)

Python: # coding: utf-8
# Your code here!
import re
while True:
    name,type = input().split()
    if type == "X":
        break
    if "_" in name:
        X = name.split("_")
    else:
        tmp = name.upper()
        name = tmp[0]+name[1:]
        X = re.findall('[A-Z][^A-Z]*',name)
    if type == "U":
        for i in range(len(X)):
            X[i] = X[i].capitalize()
    elif type == "L":
        X[0] = X[0].lower()
        for i in range(1,len(X)):
            X[i] = X[i].capitalize()
    else:
        X[0] = X[0].lower()
        for i in range(1,len(X)):
            X[i] = "_"+X[i].lower()
    print("".join(X))

Python: while True:
    a, b = input().split()
    if b == 'X':
        break

    if '_' in a:
        ans = a.split('_')
    else:
        ans = []
        j = 0
        for i in range(1, len(a)):
            if a[i].isupper():
                ans.append(a[j:i])
                j = i
        ans.append(a[j:])
        
    if b == 'D':
        ans = '_'.join(map(str.lower, ans))
    else:
        ans = ''.join(map(str.capitalize, ans))
        
        if b == 'L':
            ans = ans[0].lower() + ans[1:]

    print(ans)

Python: while True:
  n, t = input().split()
  if t == "X":
    break

  if "_" in n:
    names = n.split("_")
  else:
    n = list(n)
    for i, c in enumerate(n):
      if c.isupper():
        if i:
          n[i] = "#" + c.lower()
        else:
          n[i] = c.lower()
    names = "".join(n).split("#")

  if t == "U":
    print(*[name.title() for name in names], sep="")
  elif t == "L":
    print(*[name.title() if i !=  0 else name for i, name in enumerate(names)], sep="")
  else:
    print(*names, sep="_")

Python: import re
while True:
    n,t=map(str,input().split())
    if t == 'X':
        break
    if '_' in n :
        if t == 'D':
            print(n)
        else:
            m = n.title()
            l= re.sub('_', '',m)
            
            if t == 'U':
                print(l)
            elif t == 'L':
                p = l[0].lower() + l[1:]
                print(p)
    else:
        q = n[0].upper() + n[1:]
        r = re.findall('[A-Z][a-z]*',q)
        
        if t == 'D':
            s = '_'.join(r)
            print(s.lower())
        elif t == 'U':
            print("".join(r))
        elif t == 'L':
            u = "".join(r)
            v = u[0].lower() + u[1:]
            print(v)