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
    a=list(a)
    if ('_' in a) and (b=='U' or b=='L'):
        c=0
        for i in range(len(a)):
            if i==0 and b=='U':
                a[i]=a[i].upper()
            elif a[i]=='_':
                c+=1
            elif c==1:
                a[i]=a[i].upper()
                c=0
        a=[i for i in a if i!='_']
    elif b=='U':
        a[0]=a[0].upper()
    elif b=='L':
        a[0]=a[0].lower()
    else:
        s=0
        for i in range(len(a)):
            if i==0:
                a[0]=a[0].lower()
                s+=1
            elif a[s].isupper():
                a[s]=a[s].lower()
                a.insert(s,'_')
                s+=2
            else:
                s+=1
    for i in range(len(a)):
        if i==len(a)-1:
            print(a[i])
        else:
            print(a[i],end='')

Python: while True:
    s=list(map(str,input().split(' ')))
    if s[1]=='X':
        break
    name=list(s[0])
    der=0
    n=[]
    for i in range(1,len(name)):
        if name[i].isupper()==True:
            n.append(i)
        if name[i]=='_':
            n.append(i-der)
            der+=1
    if s[1]=='U':
        name[0]=name[0].upper()
        for u in range(len(n)):
            if name[n[u]]=='_':
                name.pop(n[u])
                name[n[u]]=name[n[u]].upper()
        print(''.join(name))
    if s[1]=='L':
        name[0]=name[0].lower()
        for l in range(len(n)):
            if name[n[l]]=='_':
                name.pop(n[l])
                name[n[l]]=name[n[l]].upper()
        print(''.join(name))
    if s[1]=='D':
        if '_' in name:
            print(''.join(name))
        else:
            name[0]=name[0].lower()
            der=0
            for d in range(len(n)):
                name[n[d]+der]=name[n[d]+der].lower()
                name.insert(n[d]+der,'_')
                der+=1
            print(''.join(name))

Python: while True:
    a, b = map(str,input().split())
    if b=='X':
        break
    if '_' in a:
        c = a.split('_')
    else:
        c=[]
        k = 0
        for i in range(1,len(a)):
            if a[i].isupper():
                c.append(a[k:i])
                k = i
        c.append(a[k:])
    if b=='D':
        c = '_'.join(map(str.lower,c))
    else:
        c = ''.join(map(str.capitalize,c))
        if b =='L':
            c = c[0].lower() + c[1:]
    print(c)

Python: import re
while True:
    n,t=input().split()
    
    if t=='X':
        break
    
    if '_'in t:
        ans=s.split('_')
    else :
        ans=re.findall(r'[a-z]+|[A-Z][a-z]*',n)
        
    if t=='D':
        ans='_'.join(map(str.lower,ans))
    else :
        ans=''.join(map(str.capitalize,ans))
        if t=='L':
            ans=ans[0].lower()+ans[1:]
    
    print(ans)

Python: while True :
    name, type = map(str, input().split())
    
    if type == "X" :
        break
    
    else :
        N = list(name)
        
        if "_" in N :
            if type == "U" or type == "L" :
                cnt = 0
                
                for i in range(len(N)) :
                    if i == 0 and type == "U" :
                        N[i] = N[i].upper()
                    elif N[i] == "_" :
                        cnt += 1
                    elif cnt == 1 :
                        N[i] = N[i].upper()
                        cnt = 0
                
                N = [i for i in N if i != "_"]
                
        elif type == "U" :
            N[0] = N[0].upper()
            
        elif type == "L" :
            N[0] = N[0].lower()
            
        else :
            s = 0
            for i in range(len(N)) :
                if i == 0 :
                    N[s] = N[s].lower()
                    s += 1
                elif N[s].isupper() :
                    N[s] = N[s].lower()
                    N.insert(s, "_")
                    s += 2
                else :
                    s += 1
            
        for i in range(len(N)) :
            if i == len(N) - 1 :
                print(N[i])
            else :
                print(N[i], end = "")

Python: import re

while True:
    s, c = input().split()
    if c == 'X':
        break

    if '_' in s:
        t = s.split('_')
    else:
        t = re.findall(r'^[a-z]+|[A-Z][a-z]*', s)

    if c == 'D':
        t = '_'.join(map(str.lower, t))
    else:
        t = ''.join(map(str.capitalize, t))
        if c == 'L':
            t = t[0].lower() + t[1:]

    print(t)

Python: import re
while True:
    n,t=input().split()
    
    if t=='X':
        break
    
    if '_'in t:
        ans=s.split('_')
    else :
        ans=re.findall(r'[a-z]+|[A-Z][a-z]*',n)
        
    if t=='D':
        ans='_'.join(map(str.lower,ans))
    else :
        ans=''.join(map(str.capitalize,ans))
        if t=='L':
            ans=ans[0].lower()+ans[1:]
    
    print(ans)