#include <iostream>
#include <string>
#include <cctype>

using namespace std;

int main(void) {
  string s;
  char c;
  while(1) {
    cin >> s >> c;
    if(c == 'X') break;
    switch(c) {
    case 'U':
      for(int i = 0; i < s.length(); i++) {
	if(i == 0) cout << (char)toupper(s[i]);
	else if(s[i] == '_') cout << (char)toupper(s[++i]);
	else cout << s[i];
      }
      break;
    case 'L':
      for(int i = 0; i < s.length(); i++) {
	if(i == 0) cout << (char)tolower(s[i]);
	else if(s[i] == '_') cout << (char)toupper(s[++i]);
	else cout << s[i];
      }
      break;
    case 'D':
      for(int i = 0; i < s.length(); i++) {
	if(i == 0) cout << (char)tolower(s[i]);
	else if(isupper(s[i])) cout << '_' << (char)tolower(s[i]);
	else cout << s[i];
      }
      break;
    }
    cout << endl;
  }

  return 0;
}