#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <sstream>
#include <cassert>
using namespace std;
static const double EPS = 1e-5;
typedef long long ll;
typedef pair<int,int> PI;
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define MP make_pair
#define PB push_back

string str;
char type;

void pr(int pos){
  if(str[pos]=='_')return;
  if(pos==0 || str[pos-1]=='_' || isupper(str[pos])){
    switch(type){
    case 'U':
      cout<<(char)toupper(str[pos]);
      break;
    case 'L':
      if(pos==0)cout<<(char)tolower(str[pos]);
      else cout<<(char)toupper(str[pos]);
      break;
    case 'D':
      if(pos==0)cout<<(char)tolower(str[pos]);
      else cout<<"_"<<(char)tolower(str[pos]);
      break;
    }
  }else{
    cout<<str[pos];
  }
}

int main(){
  while(cin>>str){
    cin>>type;
    if(type=='X')break;
    rep(i,str.size()){
      pr(i);
    }
    cout<<endl;
  }
}