#include <iostream>
#include <string>

using namespace std;

void solve()
{
	string s;
	char c;
	while(cin >> s >> c)
	{
		string ans;
		if(c == 'X')
		{
			break;
		}
		else if(c == 'L')
		{
			if('A' <= s[0] && s[0] <= 'Z')
			{
				ans += s[0] - 'A' + 'a';
			}
			else
			{
				ans += s[0];
			}
			bool underbar_flag = false;
			for(int i = 1; i < s.size(); ++i)
			{
				if(underbar_flag)
				{
					ans += s[i] - 'a' + 'A';
					underbar_flag = false;
				}
				else if(s[i] != '_')
				{
					ans += s[i];
				}
				else if(s[i] == '_')
				{
					underbar_flag = true;
				}
			}
		}
		else if(c == 'U')
		{
			if('a' <= s[0] && s[0] <= 'z')
			{
				ans += s[0] - 'a' + 'A';
			}
			else
			{
				ans += s[0];
			}
			bool underbar_flag = false;
			for(int i = 1; i < s.size(); ++i)
			{
				if(underbar_flag)
				{
					ans += s[i] - 'a' + 'A';
					underbar_flag = false;
				}
				else if(s[i] != '_')
				{
					ans += s[i];
				}
				else if(s[i] == '_')
				{
					underbar_flag = true;
				}
			}
		}
		else if(c == 'D')
		{
			if('A' <= s[0] && s[0] <= 'Z')
			{
				ans += s[0] - 'A' + 'a';
			}
			else
			{
				ans += s[0];
			}
			for(int i = 1; i < s.size(); ++i)
			{
				if('A' <= s[i] && s[i] <= 'Z')
				{
					ans += '_';
					ans += s[i] - 'A' + 'a';
				}
				else
				{
					ans += s[i];
				}
			}
		}
		cout << ans << endl;
	}
}

int main()
{
	solve();
	return(0);
}