#include <cstdio>
#include <cstring>
#include <cctype>

int main(){
	while(true){
		char str[101], cmd[2];
		scanf("%100s %1s", str, cmd);
		if(cmd[0] == 'X'){ break; }
		bool isFirst = true, isPause = true;
		for(char *p = str; *p != '\0'; p++){
			if(!isFirst){
				if(!(*p & 0x20)){ isPause = true; }
				if(*p == '_'){
					isPause = true;
					if(*++p == '\0'){ break; }
				}
			}
			switch(cmd[0]){
			case 'U':
				if(isPause){
					putc(toupper(*p), stdout);
				}else{
					putc(tolower(*p), stdout);
				}
				break;
			case 'L':
				if(isPause && !isFirst){
					putc(toupper(*p), stdout);
				}else{
					putc(tolower(*p), stdout);
				}
				break;
			case 'D':
				if(isPause && !isFirst){
					putc('_', stdout); putc(tolower(*p), stdout);
				}else{
					putc(tolower(*p), stdout);
				}
			}
			isPause = false;
			isFirst = false;
		}
		puts("");
	}
	return 0;
}