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:
    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: large = list("ABCDEFGHIJKLMNOPQRSTUVWXYZ")
small = list("abcdefghijklmnopqrstuvwxyz")

while 1:
    word, alpha = input().split()
    if alpha == "X":
        break

    word = list(word)

    ans = ""
    if alpha == "L":
        first = word.pop(0)
        if first in large:
            ans += small[large.index(first)]
        else:
            ans += first

        while word != []:
            w = word.pop(0)
            if w == "_":
                target = word.pop(0)
                if target in small:
                    ans += large[small.index(target)]
                else:
                    ans += target
            else:
                ans += w

    elif alpha == "U":
        first = word.pop(0)
        if first in small:
            ans += large[small.index(first)]
        else:
            ans += first

        while word != []:
            w = word.pop(0)
            if w == "_":
                target = word.pop(0)
                if target in small:
                    ans += large[small.index(target)]
                else:
                    ans += target
            else:
                ans += w

    elif alpha == "D":
        first = word.pop(0)
        if first in large:
            ans += small[large.index(first)]
        else:
            ans += first

        while word != []:
            w = word.pop(0)
            if w in large:
                ans += "_" + small[large.index(w)]
            else:
                ans += w

    print(ans)

Python: 
while True:
    name,typ = input().split()
    if typ=="X": break
    ans = []
    
    if "_" in name:
        ans = name.split("_")
    else:
        j = 0
        for i in range(1,len(name)):
            if name[i].isupper():
                ans.append(name[j:i])
                j = i
        ans.append(name[j:])
                
    if typ=="D":
        ans = map(str.lower, ans)
        print(*ans,sep="_")
        
    else:
        ans = "".join(map(str.capitalize, ans))
        if typ=="L":
            ans = ans[0].lower() + ans[1:]
        print(ans)

Python: while True:
    s = input()
    s, order = s.split()
    if order == 'X':
        break
    if '_' in s:
        if order == 'U':
            s = s.split('_')
            a = ''
            for i in s:
                a += i.capitalize()
            print(a)
        elif order == 'L':
            s = s.split('_')
            a = ''
            a += s[0].lower()
            for i in s[1:]:
                a += i.capitalize()
            print(a)
        else:
            print(s.lower())
    else:
        if order == 'U':
            if s[0].isupper():
                print(s)
            else:
                s = s[0].upper() + s[1:]
                print(s)
        elif order == 'L':
            if s[0].islower():
                print(s)
            else:
                s = s[0].lower() + s[1:]
                print(s)
        else: 
            index = []
            c = 0
            for i in range(len(s[1:])):
                if s[i+1].isupper():
                    index.append(i + 1+c)
                    c += 1
            for j in index:
                s = s[: j] + '_' + s[j:]
            print(s.lower())

Python: def Upper(s) :
    New = []
    i = 0
    while True :
        if i == 0 :
            New.append(s[i].upper())
        elif s[i] == "_" :
            i += 1
            New.append(s[i].upper())
        elif 65 <= ord(s[i]) <= 90 :
            New.append(s[i].upper())
        else :
            New.append(s[i].lower())
        i += 1
        if i >= len(s) :
            break
    return New

def Lower(s) :
    New = []
    i = 0
    while True :
        if s[i] == "_" :
            i += 1
            New.append(s[i].upper())
        elif 65 <= ord(s[i]) <= 90 and i != 0:
            New.append(s[i].upper())
        else :
            New.append(s[i].lower())
        i += 1
        if i >= len(s) :
            break
    return New

def Under_Score(s) :
    New = []
    i = 0
    while True :
        if 65 <= ord(s[i]) <= 90 and i != 0:
            New.append("_")
            New.append(s[i].lower())
        else :
            New.append(s[i].lower())
        i += 1
        if i >= len(s) :
            break
    return New

while True :
    l, x = map(str, input().split())
    if x == "X" :
        break
    
    elif x == "U" :
        print(*Upper(l), sep="")
    elif x == "L" :
        print(*Lower(l), sep="")
    elif x == "D" :
        print(*Under_Score(l), sep="")