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

#define iota(i,n,b,s) for(int i=int(b);i!=int((b)+(s)*(n));i+=(s))
#define range(i,n,m) iota(i,(((n)>(m))?((n)-(m)+1):((m)-(n)+1)),(n),((n)>(m)?-1:1))
#define rep(i,n) iota(i,(n),0,1)

#define INF (1e9)
#define EPS (1e-9)
#define cons(a,b) (make_pair(a,b))
#define car(a) (a.first)
#define cdr(a) (a.second)
#define cadr(a) (car(cdr(a)))
#define cddr(a) (cdr(cdr(a)))
#define all(a) a.begin(), a.end()
#define trace(var) cerr<<">>> "<<#var<<" = "<<var<<endl;

typedef long long Integer;
typedef double Real;

template<class S, class T>
ostream& operator<<(ostream& os, pair<S,T> p) {
  os << '(' << car(p) << ", " << cdr(p) << ')';
  return os;
}

template<class T>
ostream& operator<<(ostream& os, vector<T> v) {
  os << v[0];
  for (int i=1, len=v.size(); i<len; ++i) os << ' ' << v[i];
  return os;
}

int dx[] = { -1, 0, 1, 0 };
int dy[] = {  0, -1, 0, 1 };

inline bool isD(string s) { return s.find('_') != string::npos; }
inline bool isL(string s) { return !isD(s) && islower(s[0]); }
inline bool isU(string s) { return !isD(s) && isupper(s[0]); }

vector<string>
splitL(string s) {
  vector<string> ret;
  int idx = 0;
  rep(i, s.size()) {
    if (isupper(s[i])) {
      string w = char(tolower(s[idx])) + s.substr(idx + 1, i - idx - 1);
      ret.push_back(w);
      idx = i;
    }
  }
  string w = char(tolower(s[idx])) + s.substr(idx + 1, s.size() - idx - 1);
  ret.push_back(w);
  return ret;
}

vector<string>
splitU(string s) {
  return splitL(char(tolower(s[0])) + s.substr(1, s.size() - 1));
}

vector<string>
splitD(string s) {
  vector<string> ret;
  int idx = 0;
  rep(i, s.size()) {
    if (s[i] == '_') {
      ret.push_back(s.substr(idx, i - idx));
      idx = i + 1;
    }
  }
  ret.push_back(s.substr(idx, s.size() - idx));
  return ret;
}

string toL(vector<string>&v) {
  string r = v[0];
  for (int i=1; i < v.size(); ++i) {
    r += char(toupper(v[i][0])) + v[i].substr(1, v[i].size() - 1);
  }
  return r;
}

string toU(vector<string>&v) {
  string r = "";
  for (int i=0; i < v.size(); ++i) {
    r += char(toupper(v[i][0])) + v[i].substr(1, v[i].size() - 1);
  }
  return r;
}

string toD(vector<string>&v) {
  string r = v[0];
  for (int i=1; i < v.size(); ++i) {
    r += "_" + v[i];
  }
  return r;
}

int main() {

more:
  string s, t;
  cin >> s >> t;
  
  if (t == "X") return 0;

  vector<string> v;
  if (isL(s)) {
    v = splitL(s);
  } else if (isU(s)) {
    v = splitU(s);
  } else if (isD(s)) {
    v = splitD(s);
  }

  if (t == "U") {
    cout << toU(v) << endl;
  } else if (t == "L") {
    cout << toL(v) << endl;
  } else if (t == "D") {
    cout << toD(v) << endl;
  }

  goto more;
}