using System;
using System.Linq;
using System.Collections.Generic;


namespace Test1 {

    class ClassMain {

        public static void Main(String[] args) {
            string line;
            while ((line = Console.ReadLine()) != null) {
                //int[] ints = line.Split(' ').Select(int.Parse).ToArray();
                //int n = int.Parse(line);
                //if(n==0){break;}
                if (line.EndsWith("X")) { break; }
                string[] strs = line.Split(' ');

                string syuyaku = strs[0];
                string dekita = "";
                if (syuyaku.Contains('_')) {
                    //under-score
                    if(strs[1].Equals("D")){
                        //nothing.
                        dekita = syuyaku;
                    }
                    else if (strs[1].Equals("U")) {
                        string tmp = "";
                        string[] strs2 = syuyaku.Split('_');
                        for (int i = 0; i < strs2.Length; i++) {
                            char sentou = char.ToUpper(strs2[i][0]);
                            tmp += sentou + strs2[i].Substring(1);
                        }
                        dekita = tmp;
                    }
                    else if (strs[1].Equals("L")) {
                        string tmp = "";
                        string[] strs2 = syuyaku.Split('_');
                        tmp += strs2[0];
                        for (int i = 1; i < strs2.Length; i++) {
                            char sentou = char.ToUpper(strs2[i][0]);
                            tmp += sentou + strs2[i].Substring(1);
                        }
                        dekita = tmp;
                    }
                }
                else if (char.IsLower(syuyaku[0])) {
                    //lower camle case
                    if (strs[1].Equals("D")) {
                        //under-score
                        List<string> stlis = new List<string>();
                        string buff = syuyaku[0]+"";
                        for (int i = 1; i < syuyaku.Length; i++) {
                            if (char.IsLower(syuyaku[i])) {
                                buff += syuyaku[i];
                            }
                            else { //uppercase
                                stlis.Add(buff);
                                buff = "";
                                buff += char.ToLower(syuyaku[i]);                                
                            }
                        }
                        stlis.Add(buff);
                        for (int i = 0; i < stlis.Count; i++) {
                            dekita += stlis.ElementAt(i);
                            if (i != stlis.Count - 1) {
                                dekita += "_";
                            }
                        }                        
                    }
                    else if (strs[1].Equals("U")) {
                        //upper
                        char sentou = char.ToUpper(syuyaku[0]);
                        dekita = sentou + syuyaku.Substring(1);
                    }
                    else if (strs[1].Equals("L")) {
                        dekita = syuyaku;
                    }

                }
                else if (char.IsUpper(syuyaku[0])) {
                    //upper camle case
                    if (strs[1].Equals("D")) {
                        //under-score
                        List<string> stlis = new List<string>();
                        string buff = char.ToLower(syuyaku[0]) + "";
                        for (int i = 1; i < syuyaku.Length; i++) {
                            if (char.IsLower(syuyaku[i])) {
                                buff += syuyaku[i];
                            }
                            else { //uppercase
                                stlis.Add(buff);
                                buff = "";
                                buff += char.ToLower(syuyaku[i]);
                            }
                        }
                        stlis.Add(buff);
                        for (int i = 0; i < stlis.Count; i++) {
                            dekita += stlis.ElementAt(i);
                            if (i != stlis.Count - 1) {
                                dekita += "_";
                            }
                        }
                    }
                    else if (strs[1].Equals("L")) {
                        //lower
                        char sentou = char.ToLower(syuyaku[0]);
                        dekita = sentou + syuyaku.Substring(1);
                    }
                    else if (strs[1].Equals("U")) {
                        //upper
                        dekita = syuyaku;
                    }

                }//henkei owari.
                Console.WriteLine(dekita);
            }   
        }   
    }
}

Measured memory_bytes: 6860