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<vector>
#include<string>
#include<queue>
using namespace std;
queue<char>stToQu(string str){
    queue<char>q;
    for(int i = 0;i < str.size();i++){
        q.push(str[i]);
    }
    return q;
}
string CamelCase(vector<string>words){
    string str;
    str += words[0];
    for(int i = 1;i < words.size();i++){
        string a = words[i];
        a[0] -= 0x20;
        str += a;
    }
    return str;
}
string UnderScore(vector<string>words){
    string str;
    str += words[0];
    for(int i = 1;i < words.size();i++){
        str += "_";
        str += words[i];
    }
    return str;
}
string solve(string str,char type){
    //cout << str;
    vector<string>words;
    queue<char> q = stToQu(str);
    string a = "";
    while(!q.empty()){
        string word;
        word = "";
        word += a;
        a = "";
        while(!q.empty()){
            char s = q.front();
            q.pop();
            //cout << s << "*" <<endl;
            if(s <= 'Z'){
                a.push_back(s + 0x20);
                break;
            }
            if(s == '_'){
                a = "";
                break;
            }
            word.push_back(s);
            //cout << "*" <<endl;
        }
        
        if(!word.empty())words.push_back(word);
    }
    if(!a.empty())words.push_back(a);
    //for(int i= 0;i < words.size();i++)cout << words[i] <<endl;
    string st;
    //cout << type <<endl;
    switch (type){
        case 'U':
            st = CamelCase(words);
            st[0] -= 0x20;
            break;
        case 'L':
            st = CamelCase(words);
            break;
        case 'D':
            st = UnderScore(words);
            break;
    }
    return st;
}
int main(){
    vector<string> a;
    while(1){
        string str;
        char type;
        cin >> str >> type;
        if(type == 'X')break;
        a.push_back(solve(str,type));
    }
    for(int i = 0;i < a.size();i++){
        cout << a[i] <<endl;
    }
    return 0;
}

C++: #include <iostream>

int main(){

    return 0;
}

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

char low(char x){return ('A'<=x && x<='Z')?x+32:x;}
char up(char x){return ('a'<=x && x<='z')?x-32:x;}

int main(){
  string s;
  char o;

  while(cin >> s >> o && o!='X'){
    cout << ((o-'U')?low(s[0]):up(s[0]));

    for(int i=1;i<(int)s.size();i++){
      if(s[i]=='_' && o-'D'){
	s.erase(s.begin()+i);
	cout << up(s[i]);
      }else if('A'<=s[i] && s[i]<='Z' && o=='D'){
	cout << '_' << low(s[i]);
      }else cout << s[i];
    }
    cout << endl;
  }
}

C++: #include <algorithm>
#include <iostream>
#define between(a,x,b) ((a)<=(x)&&(x)<=(b))
using namespace std;

int main(){
  int i=0;
  string s,t;
  for(;cin >> s >> t,t!="X";){
  if(find(s.begin(),s.end(),'_')!=s.end()){
    for(i=0;i<s.length();i++)
      if(s[i]=='_'){
        if(s[i+1]=='_'||s[i+1]==0){cout << "Error!" << endl;return 0;}
        s.erase(i,1),s[i]-=0x20;
      }
    if(t=="U")s[0]-=0x20;
    cout << s << endl;
  }else{
    if(between('A',s[0],'Z'))s[0]+=0x20;
    if(t=="U")s[0]-=0x20;
    if(t=="D")
      for(i=0;i<s.length();i++)
        if(between('A',s[i],'Z'))s.insert(i,1,'_'),s[++i]+=0x20;
    cout << s << endl;
  }
  }
}

C++: #include <bits/stdc++.h>
using namespace std;
#define all(c) (c).begin(),(c).end()
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define iter(c) __typeof((c).begin())
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
#define mem(a) memset(a,0,sizeof(a))
#define pd(a) printf("%.10f\n",a)
#define pb(a) push_back(a)
#define in(a) insert(a)
#define pi M_PI
#define R cin>>
#define F first
#define S second
#define C class
#define ll long long
#define ln cout<<'\n'
template<C T>void pr(T a){cout<<a;ln;}
template<C T,C T2>void pr(T a,T2 b){cout<<a<<' '<<b;ln;}
template<C T,C T2,C T3>void pr(T a,T2 b,T3 c){cout<<a<<' '<<b<<' '<<c;ln;}
template<C T>void PR(T a,int n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
bool check(int n,int m,int x,int y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1000000007,MAXL=1LL<<60,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<int,int> P;

void Main() {
  string s,t;
  while(cin >> s >> t && t!="X") {
    vector<string> v;
    string r="";
    s+='_';
    rep(i,s.size()) {
      if(isupper(s[i])) {
        if(r.size()) v.pb(r);
        r=tolower(s[i]);
      } else if(s[i]=='_') {
        if(r.size()) v.pb(r);
        r="";
      } else r+=s[i];
    }
    string ans="";
    if(t=="L") {
      rep(i,v.size()) {
        if(i) v[i][0]=toupper(v[i][0]);
        ans+=v[i];
      }
    } else if(t=="U") {
      rep(i,v.size()) {
        v[i][0]=toupper(v[i][0]);
        ans+=v[i];
      }
    } else {
      rep(i,v.size()) {
        if(i) ans+='_';
        ans+=v[i];
      }
    }
    pr(ans);
  }
}

int main() {
  ios::sync_with_stdio(0);cin.tie(0);
  Main();return 0;
}