#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <cmath>
#include <cassert>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <numeric>
#include <complex>
#include <list>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <utility>
#include <functional>
#include <iterator>

using namespace std;

#define dump(n) cerr<<"# "<<#n<<"="<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define iter(c) __typeof__((c).begin())
#define foreach(i,c) for(iter(c) i=(c).begin();i!=(c).end();++i)
#define all(c) (c).begin(),(c).end()
#define mp make_pair

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<string> vs;
typedef pair<int,int> pii;

int main()
{
	for(string s,t;cin>>s>>t,t!="X";){
		vs ss;
		for(int i=0,j=1;i<s.size();j++){
			if(j==s.size() || isupper(s[j])){
				ss.push_back(s.substr(i,j-i));
				i=j;
			}
			if(s[j]=='_'){
				ss.push_back(s.substr(i,j-i));
				i=++j;
			}
		}
		if(t=="U")
			rep(i,ss.size())
				rep(j,ss[i].size())
					putchar(j==0?toupper(ss[i][j]):tolower(ss[i][j]));
		if(t=="L")
			rep(i,ss.size())
				rep(j,ss[i].size())
					putchar(i&&j==0?toupper(ss[i][j]):tolower(ss[i][j]));
		if(t=="D")
			rep(i,ss.size()){
				cout<<(i?"_":"");
				rep(j,ss[i].size())
					putchar(tolower(ss[i][j]));
			}
		cout<<endl;
	}
	
	return 0;
}