#define _CRT_SECURE_NO_WARNINGS
//#define _USE_MATH_DEFINES
#include<stdio.h>
//#include<stdlib.h>
//#include<math.h>
#include<string.h>
//#include<time.h>
#include<ctype.h>
//#define pi acos(-1.0)
#define P(type,x) fprintf(stdout,"%"#type"\n",x)
#define S(type,x) fscanf(stdin,"%"#type,&x)
void U();
void D();
char name[128],t[128];
int main(){
	char type;
	while (~fscanf(stdin, "%s %c%\n", name, &type),type!='X') {
		memset(t, 0, sizeof(t));
		switch (type){
		case 'L':
			U();
			t[0] = tolower(t[0]);
			break;
		case 'U':
			U();
			t[0] = toupper(t[0]);
			break;
		case 'D':
			D();
		}
		P(s, t);
	}
	return 0;
}

void U(){
	int i, j;
	for(i=j=0;name[i];i++)
		if (name[i] == '_') name[i + 1] -= 0x20;
		else t[j++] = name[i];
}

void D(){
	int i, j;
	for (i = j = 0; name[i]; i++)
		if (i&&name[i] != '_'&&name[i]<'a') t[j++] = '_', t[j++] = tolower(name[i]);
		else t[j++] = tolower(name[i]);
}