#include <iostream>
#include <vector>
using namespace std;

string upperCamel(string& s){
	return (char)(s[0]-'a'+'A')+s.substr(1,s.size());
}

int main(void){
	string s;
	while(cin>>s){
		char c;cin>>c;
		if(c=='X')break;
		vector<string> splited;
		string tmp;
		for(int i=0;i<s.size();++i){
			if('A'<=s[i]&&s[i]<='Z'){
				if(i==0){
					tmp+=s[i]-'A'+'a';
					continue;
				}
				splited.push_back(tmp);
				tmp=s[i]-'A'+'a';
			}else if(s[i]=='_'){
				splited.push_back(tmp);
				tmp="";
			}else tmp+=s[i];
		}
		splited.push_back(tmp);
		if(c=='L'){
			for(int i=0;i<splited.size();++i){
				if(i) cout<<upperCamel(splited[i]);
				else cout<<splited[i];
			}
			cout<<endl;
		}else if(c=='U'){
			for(int i=0;i<splited.size();++i){
				cout<<upperCamel(splited[i]);
			}
			cout<<endl;
		}else if(c=='D'){
			for(int i=0;i<splited.size();++i){
				if(i)cout<<"_";
				cout<<splited[i];
			}
			cout<<endl;
		}
	}
	return 0;
}