#include <iostream>
#include <string>

using namespace std;

string UOP(string str){
  string ans="";
  if('a' <= str[0] && str[0] <= 'z') str[0] = toupper(str[0]);
  for(int i = 0 ; i < str.size() ; i++){
    if(str[i] == '_'){
      if('a' <= str[i+1] && str[i+1] <= 'z') str[i+1] = toupper(str[i+1]);
    }
    else ans += str[i];
  }
  return ans;
}

string LOP(string str){
  string ans="";
  if('A' <= str[0] && str[0] <= 'Z') str[0] = tolower(str[0]);
  for(int i = 0 ; i < str.size() ; i++){
    if(str[i] == '_'){
      if('a' <= str[i+1] && str[i+1] <= 'z') str[i+1] = toupper(str[i+1]);
    }
    else ans += str[i];
  }
  return ans;
}

string DOP(string str){
  string ans="";
  for(int i = 0 ; i < str.size() ; i++){
    if('A' <= str[i] && str[i] <= 'Z') str[i] = tolower(str[i]);
    ans += str[i];
    if('A' <= str[i+1] && str[i+1] <= 'Z') ans += '_';
  }
  return ans;
}

int main(){
  string str;
  char op;
  while(cin >> str >> op, op != 'X'){
    if(op == 'U'){
      cout << UOP(str) << endl;
    }
    else if(op == 'L'){
      cout << LOP(str) << endl;
    }
    else if(op == 'D'){
      cout << DOP(str) << endl;
    }
  }
  return 0;
}