#include <bits/stdc++.h>
using namespace std;

using State = string::const_iterator;

string expr(State &itr, int mode){
    string res = "";
    res.push_back(*itr);
    ++itr;
    if(mode==0){
        res[0] = toupper(res[0]);
    }else{
        res[0] = tolower(res[0]);
    }
    while(1){
        if(islower(*itr)){
            res.push_back(*itr);
            ++itr;
        }else{
            break;
        }
    }
    if(mode==0 || mode==1){
        if(*itr == '_') ++itr;
    }else{
        if(isalpha(*itr)) res.push_back('_');
    }
    return res;
}

int main(){
    string s;
    char op;
    while(cin >> s >> op){
        if(op == 'X') break;
        string ans = "";
        int m;
        if(op == 'U') m = 0;
        if(op == 'L') m = 1;
        if(op == 'D') m = 2;
        State begin = s.begin();
        while(begin != s.end()){
            ans += expr(begin,m);
            if(m==1) m = 0;
        }
        cout << ans << endl;
    }
    return 0;
}

