#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

string solve(string s, char c){
    if('A' <= s[0] && s[0] <= 'Z')
        s[0] += 'a' - 'A';
    s += '_';
    int n = s.size();

    int j = 0;
    vector<string> vs;
    for(int i=0; i<n; ++i){
        if('A' <= s[i] && s[i] <= 'Z'){
            s[i] += 'a' - 'A';
            vs.push_back(s.substr(j, i-j));
            j = i;
        }else if(s[i] == '_'){
            vs.push_back(s.substr(j, i-j));
            j = i+1;
        }
    }

    int m = vs.size();
    if(c == 'U')
        vs[0][0] += 'A' - 'a';
    s = vs[0];

    for(int i=1; i<m; ++i){
        if(c == 'D'){
            s += '_' + vs[i];
        }else{
            vs[i][0] += 'A' - 'a';
            s += vs[i];
        }
    }
    return s;
}

int main()
{
    for(;;){
        string s;
        char c;
        cin >> s >> c;
        if(s == "EndOfInput")
            return 0;

        cout << solve(s, c) << endl;
    }
}