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

int i, j;

vector <string> word(string str);

int main(void)
{
	string str;
	char type;
	while (cin >> str >> type, type != 'X'){
		int flag = 0;
		vector <string> vs = word(str);
		if (type == 'L'){
			cout << vs[0];
			for (i = 1; i < vs.size(); i++){
				vs[i][0] ^= 32;
				cout << vs[i];
			}
			puts("");
		}
		if (type == 'U'){
			for (i = 0; i < vs.size(); i++){
				vs[i][0] ^= 32;
				cout << vs[i];
			}
			puts("");
		}
		if (type == 'D'){
			for (i = 0; i < vs.size(); i++){
				cout << vs[i];
				if (i + 1 != vs.size()) cout << "_";
			}
			puts("");
		}
	}
	
	return 0;
}

vector <string> word(string str)
{
	vector <string> vs;
	bool flag = false;
	for (i = 0; i < str.size(); i++){
		if (str[i] == '_') {
			flag = true;
			break;
		}
	}
	
	string tmp;
	if (flag){
		for (i = 0; i < str.size(); i++){
			if (str[i] != '_'){
				tmp += (str[i] |= 32);
			}
			else {
				vs.push_back(tmp);
				tmp.clear();
			}
		}
		vs.push_back(tmp);
		return vs;
	}
	
	if ('a' <= str[0] && str[0] <= 'z'){
		for (i = 0; i < str.size(); i++){
			if (!('A' <= str[i] && str[i] <= 'Z')){
				tmp += (str[i] |= 32);
			}
			else {
				vs.push_back(tmp);
				tmp.clear();
				break;
			}
		}
		for (; i < str.size(); i++){
			tmp += (str[i] |= 32);
			if (('A' <= str[i + 1] && str[i + 1] <= 'Z') && i + 1 < str.size()){
				vs.push_back(tmp);
				tmp.clear();
			}
		}
		vs.push_back(tmp);
		return vs;
	}
	
	if ('A' <= str[0] && str[0] <= 'Z'){
		for (i = 0; i < str.size(); i++){
			tmp += (str[i] |= 32);
			if (('A' <= str[i + 1] && str[i + 1] <= 'Z') && i + 1 < str.size()){
				vs.push_back(tmp);
				tmp.clear();
			}
		}
		vs.push_back(tmp);
		return vs;
	}
	
	return vs;
}
	