#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main() {
	string s;
	char c;
	string abc = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
	string abc2 = "abcdefghijklmnopqrstuvwxyz";
	while (cin >> s >> c) {
		if (c == 'X') {
			break;
		}
		vector<string> ss;
		if (s.find("_") != string::npos) {
			string sa = "";
			for (int i = 0; i < s.size(); i++) {
				if (s[i] == '_') {
					ss.push_back(sa);
					sa = "";
				} else {
					sa += s[i];
				}
			}
			ss.push_back(sa);
		} else {
			bool h = false;
			for (int i = 0; i < 26; i++) {
				if (s[0] == abc[i]) {
					h = true;
					break;
				}
			}
			if (h) {
				string sb = "";
				for (int i = 0; i < s.size(); i++) {
					bool h2 = false;
					for (int j = 0; j < 26; j++) {
						if (s[i] == abc[j]) {
							h2 = true;
							if (sb == "") {
							} else {
								ss.push_back(sb);
							}
							sb = "";
							sb += abc2[j];
							break;
						}
					}
					if (!h2) {
						sb += s[i];
					}
				}
				ss.push_back(sb);
			} else {
				string sc = "";
				for (int i = 0; i < s.size(); i++) {
					bool h2 = false;
					for (int j = 0; j < 26; j++) {
						if (s[i] == abc[j]) {
							h2 = true;
							ss.push_back(sc);
							sc = "";
							sc += abc2[j];
							break;
						}
					}
					if (!h2) {
						sc += s[i];
					}
				}
				ss.push_back(sc);
			}
		}
		string s2 = "";
		if (c == 'U') {
			for (int i = 0; i < ss.size(); i++) {
				for (int j = 0; j < 26; j++) {
					if (ss[i][0] == abc2[j]) {
						ss[i][0] = abc[j];
						break;
					}
				}
				s2 += ss[i];
			}
		} else if (c == 'L') {
			s2 += ss[0];
			for (int i = 1; i < ss.size(); i++) {
				for (int j = 0; j < 26; j++) {
					if (ss[i][0] == abc2[j]) {
						ss[i][0] = abc[j];
						break;
					}
				}
				s2 += ss[i];
			}
		} else {
			for (int i = 0; i < ss.size(); i++) {
				if (s2 != "") {
					s2 += "_";
				} 
				s2 += ss[i];
			}
		}
		cout << s2 << endl;
	}
	return 0;
}