#include <stdio.h>
#include <ctype.h>
char ans[101];
void UL(char line[],char type){
    int i=1,t=1;
    ans[0]=type=='U'?toupper(line[0]):tolower(line[0]);
    while(line[i]){
        if(line[i] == '_'){
            ans[t++]=toupper(line[++i]);
            i++;
        }
        else ans[t++]=line[i++];
    }
    ans[t]=0;
}
void D(char line[]){
    int i=1,t=1;
    ans[0]=tolower(line[0]);
    while(line[i]){
        if(isupper(line[i])){
            ans[t++]='_';
            ans[t++]=tolower(line[i++]);
        }
        else ans[t++]=line[i++];
    }
    ans[t]=0;
}

int main(void){
    char line[101],type;
    for(;scanf("%s %s",line,&type),type != 'X';){
        type=='D'?D(line):UL(line,type);
        printf("%s\n",ans);
    }
    return 0;
}