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, "_")
}

C++: #include<iostream>
#include<string>
using namespace std;
string S; char C;
int main() {
	while (true) {
		cin >> S >> C; string D;
		if (C == 'X')break;
		if (C == 'L' || C == 'U') {
			for (int i = 0; i < S.size(); i++) {
				if (S[i] == '_') {
					i++; if (S[i] <= 'Z')D += S[i];
					else D += (char)(S[i] - 32);
				}
				else {
					if (S[i] > 'Z')D += S[i];
					else D += (char)(S[i] + 32);
				}
			}
			if (S[0] <= 'Z')S[0] += 32;
		}
		if (C == 'U') {
			if (S[0] > 'Z')S[0] -= 32;
		}
		if (C == 'D') {
			for (int i = 0; i < S.size(); i++) {
				if (S[i] <= 'Z' && i >= 1) { D += '_'; }
				if (S[i] <= 'Z') { D += (char)(S[i] + 32); }
				else { D += S[i]; }
			}
		}
		cout << D << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <string>
using namespace std;

int dif='a'-'A';
void outU( string &s ){
  char c;
  for(unsigned int i=0;i<s.size();i++ ){
    c=s.at( i );
    if( i==0 ) c-= dif;
    cout << c;
  }
}

int main(){
  string name, type;
  string names[100];
  int nw;

  while( true ){
    cin >> name >> type;
    //    cout << name << "," << type << endl;

    if( type=="X" ) break;

    for( int i=0;i<100;i++ )names[i]="";

    nw=0;
    char c;
    for( unsigned int i=0; i<name.size();i++ ){
      c = name.at(i);
      if( c== '_' ) nw++;
      else if( c<='Z'){
	c+= dif;
	if( names[nw].size()!=0 ){
	  nw++; names[nw]="";
	}
	names[nw] += c;
      }else
	names[nw] += c;
    }
    if( c!='_' )
      nw++;

    //    cout << "\ndiv "<<name<<endl;
    // for( int i=0;i<nw;i++ )      cout << names[i] << endl;

    if( type=="D" ){
      int i;
      for( i=0;i<nw-1;i++ )
	cout << names[i] << "_" ;
      cout << names[i] << endl;
    }else{
      if( type=="U" ) // ツ渉可づ淞づ個閉カツ篠堋療アツづ債陛渉環キ
	outU( names[0] );
      else
	cout << names[0];
      for( int i=1;i<nw;i++ )
	outU( names[i] );
      cout << endl;
    }
  }

  return 0;
}

C++: #include<iostream>
#include<string>
using namespace std;

int main(){
  string str;
  char S;
  while(1){
    cin>>str;
    cin>>S;

    if(S=='X') break;

    else  if(S=='L'){
      if(str[0]>='A' && str[0]<='Z') str[0]+=32;
      for(int i=0;i<str.size()-1;i++){
	if(str[i]=='_' && str[i+1]>='a' && str[i+1]<='z' ) str[i+1]-=32;
      }
      for(int i=0;i<str.size();i++){
	if(str[i]=='_') continue;
	else cout<<str[i];
      }
      cout<<endl;
    }
    
    else  if(S=='U') {
      if(str[0]>='a' && str[0]<='z') str[0]-=32;
    
    for(int i=0;i<str.size()-1;i++){
    if(str[i]=='_'&& str[i+1]>='a' && str[i+1]<='z') str[i+1]-=32;
  }
  for(int i=0;i<str.size();i++){
	if(str[i]=='_') continue;
	else cout<<str[i];
      }
      cout<<endl;
      
    }
    
  else  if(S=='D'){
    for(int i=0;i<str.size();i++){
      if(str[i]>=65 && str[i]<=90){
	str[i]+=32;
      }
      if(i>0 && i<str.size()-1 && str[i+1]>=65 && str[i+1]<=90){
	cout<<str[i]<<"_";
      }
      else cout<<str[i];
    }
    cout<<endl;
  }
  }
  return 0;
  }

C++: #include <cctype>
#include <cstdio>
#include <iostream>
#include <sstream>
#include <string>
using namespace std;

char SmallToLarge(char x){
	return x-'a'+'A';
}

char LargeToSmall(char x){
	return x-'A'+'a';	
}

int main(){
	string s;
	char c;
	while(cin >> s >> c){
		if(c=='X') break;
		
		string t=s;
		//UpperCmaelCase??????
		if('a'<=s[0] && s[0]<='z'){
			bool underscore=false;
			for(int i=0; i<s.size(); ++i){
				if(s[i]=='_'){
					underscore=true;
					break;	
				}	
			}	
			
			stringstream ss;
			ss << SmallToLarge(s[0]);
			
			if(underscore){
				for(int i=1; i<s.size(); ++i){
					if(s[i]=='_') continue;
					
					if(s[i-1]=='_') ss << SmallToLarge(s[i]);
					else ss << s[i];
				}
			}
			else for(int i=1; i<s.size(); ++i) ss << s[i];	
			
			t=ss.str();
		}
		
		//cout << t <<endl;
		
		if(c=='L') t[0]=t[0]-'A'+'a';
		else if(c=='D'){
			stringstream tt;
			tt<<LargeToSmall(t[0]);
			for(int i=1; i<t.size(); ++i){
				if('A'<=t[i] && t[i]<='Z'){
					tt<<'_';
					tt<<LargeToSmall(t[i]);	
				}
				else tt<<t[i];	
			}
			
			t=tt.str();
		}
		
		cout << t <<endl;		
		
	}
}