#include<stdio.h>
int main(){
  char s[102];
  char w;
  int i;
  while(scanf(" %s %c",s,&w),w!='X'){
    if(w=='U')printf("%c",toupper(s[0]));
    else      printf("%c",tolower(s[0]));
    for(i=1;s[i];i++){
      if('a'<=s[i]&&s[i]<='z'){
	printf("%c",s[i]);
      }
      else{
	if(s[i]=='_')i++;
	if(w=='D')printf("_%c",tolower(s[i]));
	else      printf("%c" ,toupper(s[i]));
      }
    }
    printf("\n");
  }
  return 0;
}