#include <iostream>
#include <string>
using namespace std;

int dif='a'-'A';
void outU( string &s ){
  char c;
  for(unsigned int i=0;i<s.size();i++ ){
    c=s.at( i );
    if( i==0 ) c-= dif;
    cout << c;
  }
}

int main(){
  string name, type;
  string names[100];
  int nw;

  while( true ){
    cin >> name >> type;
    //    cout << name << "," << type << endl;

    if( type=="X" ) break;

    for( int i=0;i<100;i++ )names[i]="";

    nw=0;
    char c;
    for( unsigned int i=0; i<name.size();i++ ){
      c = name.at(i);
      if( c== '_' ) nw++;
      else if( c<='Z'){
	c+= dif;
	if( names[nw].size()!=0 ){
	  nw++; names[nw]="";
	}
	names[nw] += c;
      }else
	names[nw] += c;
    }
    if( c!='_' )
      nw++;

    //    cout << "\ndiv "<<name<<endl;
    // for( int i=0;i<nw;i++ )      cout << names[i] << endl;

    if( type=="D" ){
      int i;
      for( i=0;i<nw-1;i++ )
	cout << names[i] << "_" ;
      cout << names[i] << endl;
    }else{
      if( type=="U" ) // テつ湘つ嘉つづδ淌つづδ古つ陛つカテつ偲つ堙つ療δアテつづδ催つ陛δ湘つ甘つキ
	outU( names[0] );
      else
	cout << names[0];
      for( int i=1;i<nw;i++ )
	outU( names[i] );
      cout << endl;
    }
  }

  return 0;
}