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: from string import ascii_uppercase
while 1:
    s, t = input().split()
    if t == 'X':
        break
    if "_" in s:
        W = s.split("_")
    else:
        W = []; w = []
        for c in s:
            if c in ascii_uppercase:
                if w:
                    W.append("".join(w).lower())
                w = [c]
            else:
                w.append(c)
        if w:
            W.append("".join(w).lower())
    if t == 'D':
        print(*W, sep='_')
    elif t == 'U':
        print(*map(lambda x: x.capitalize(), W), sep='')
    else:
        print(W[0], *map(lambda x: x.capitalize(), W[1:]), sep='')

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:
            c = c[0].lower() + 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: while True:
    s, cc = input().split()
    if cc == "X":break
    if "_" in s:
        t = s.split("_")
    else:
        t = []
        j = 0
        for i in range(1, len(s)):
            if s[i].isupper():
                t.append(s[j:i])
                j = i
        t.append(s[j:])
    if cc == "U":
        for i in range(len(t)):t[i] = t[i][0].upper() + t[i][1:]
        print("".join(t))
    elif cc == "L":
        t[0] = t[0].lower()
        for i in range(1, len(t)):t[i] = t[i][0].upper() + t[i][1:]
        print("".join(t))
    else:
        for i in range(len(t)):t[i] = t[i].lower()
        print("_".join(t))

Python: # AOJ 1044: CamelCase
# Python3 2018.7.6 bal4u

while True:
	n, t = input().split()
	if t == 'X': break
	ans, n = '', list(n)
	if t == 'U':
		ans += n.pop(0).upper()
		while n != []:
			while n != [] and n[0] != '_': ans += n.pop(0)
			if len(n) > 1 and n[0] == '_':
				del n[0]
				ans += n.pop(0).upper()
	elif t == 'L':
		ans += n.pop(0).lower()
		while n != []:
			while n != [] and n[0] != '_': ans += n.pop(0)
			if len(n) > 1 and n[0] == '_':
				del n[0]
				ans += n.pop(0).upper()
	else:
		ans += n.pop(0).lower()
		while n != []:
			while n != [] and n[0].isupper() == False: ans += n.pop(0)
			if n != [] and n[0].isupper(): ans += '_' + n.pop(0).lower()
	print(ans)

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:
    Name, Type = input().split()
    
    if Type=='X':
        break
    
    if '_' in Name:
        
        Name_ = Name
        _n_ = [0]
        i = 0
        while True:
            Namelist_ = list(Name_)
            n_ = Name_.find('_')
            if n_==-1:
                break
            _n_.append(n_+_n_[i])
            i += 1
            del(Namelist_[0:n_+1])
            Name_ = ''.join(Namelist_)
        
        Name = ''.join(Name.split('_'))
        Namelist = list(Name)
        for i in range(len(_n_)):
            o = str(Namelist[_n_[i]])
            O = o.upper()
            Namelist.pop(_n_[i])
            Namelist.insert(_n_[i],O)
        Name = ''.join(Namelist)
        
    if Type=='U':
        NameLIST = list(Name)
        o = str(NameLIST[0])
        O = o.upper()
        NameLIST.pop(0)
        NameLIST.insert(0,O)
        NAME = ''.join(NameLIST)
    
    if Type=='L':
        NameLIST = list(Name)
        O = str(NameLIST[0])
        o = O.lower()
        NameLIST.pop(0)
        NameLIST.insert(0,o)
        NAME = ''.join(NameLIST)
    
    if Type=='D':
        NameLIST = list(Name)
        _T_ = []
        t = 0
        for i in range(len(NameLIST)):
            T = str(NameLIST[i])
            if T.isupper()==False:
                pass
            if T.isupper()==True:
                if i==0:
                    pass
                if i>0:
                    _T_.append(i+t)
                    t += 1
                Tt = T.lower()
                NameLIST.pop(i)
                NameLIST.insert(i,Tt)
        for i in range(len(_T_)):
            NameLIST.insert(_T_[i],'_')
        NAME = ''.join(NameLIST)
        
    
    print(NAME)