#include <iostream>
#include <cstdio>
#include <string>
#include <sstream>
#include <algorithm>
#include <math.h>
#include <map>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>

#define PI 3.14159265359

#define INF 99999999;

#define rep(i, n) for(int i=0; i<n; i++)
#define REP(n) rep(i, n)

typedef long long ll;

using namespace std;



/*
class LightSwitchingPuzzle
{
public:
	int minFlips(string s)
	{

	}
}
*/

string get_underscore(string inp)
{
	if (inp.find("_") != string::npos)
	{
		return inp;
	}
	
	if (inp[0] < 'a') inp[0] += 32;
	string ret = "";
	for (int i=0; i<inp.length(); i++)
	{
		if (inp[i] < 'a')
		{
			char c = inp[i] + 32;
			ret = ret + "_" + c;
		} else {
			ret += inp[i];
		}
	}
	
	return ret;
}

string upper_camel_case(string inp)
{
	char c = inp[0] - 32;
	string ret = "";
	
	ret += c;
	
	for (int i=1; i<inp.length(); i++)
	{
		if (inp[i] == '_')
		{
			ret += inp[i+1] - 32;
			i++;
		} else {
			ret += inp[i];
		}
	}
	
	return ret;
}

string lower_camel_case(string inp)
{
	string ret = "";
	
	for (int i=0; i<inp.length(); i++)
	{
		if (inp[i] == '_')
		{
			ret += inp[i+1] - 32;
			i++;
		} else {
			ret += inp[i];
		}
	}
	
	return ret;
}

int main()
{
	string name;
	char type;
	
	while (cin >> name >> type)
	{
		if (type == 'X') break;
		
		name = get_underscore(name);
		
		switch (type)
		{
		case 'U':
			cout << upper_camel_case(name) << endl;
			break;
		case 'L':
			cout << lower_camel_case(name) << endl;
			break;
		case 'D':
			cout << name << endl;
			break;
		}
	}
	
	//cout << upper_camel_case("get_user_name") << endl;
	
	return 0;
}