#include<iostream>
#include<vector>
#include<cctype>
#include<sstream>

using namespace std;

vector<string> parse(const string &str){
  vector<string> ret;

  stringstream ss;

  for(int i = 0; i <= str.size(); i++){
    if(i == str.size()){
      ret.push_back(ss.str());
      ss.str("");
    }else if(str[i] == '_'){
      ret.push_back(ss.str());
      ss.str("");
    }else if(isupper(str[i])){
      if(ss.str().size() > 0) ret.push_back(ss.str());
      ss.str("");
      ss << (char)tolower(str[i]);
    }else{
      ss << str[i];
    }
  }

  return ret;
}

string convert(const vector<string> &v, char dist){
  stringstream ss;

  bool first = true;

  for(int i = 0; i < v.size(); i++){
    string tmp = v[i];
    
    if(dist == 'U'){
      tmp[0] = toupper(tmp[0]);
    }else if(dist == 'L'){
      if(!first) 
	tmp[0] = toupper(tmp[0]);
    }else if(dist == 'D'){
      if(!first)
	tmp = "_" + tmp;
    }

    ss << tmp;
    first = false;
  }

  return ss.str();
}

int main(){
  string buff;
  char dist;

  while(cin >> buff >> dist, dist != 'X'){
    cout << convert(parse(buff), dist) << endl;
  }

  return 0;
}