import std.stdio, std.string, std.conv, std.regex, std.algorithm, std.array;

immutable int L = 0;
immutable int U = 1;
immutable int D = 2;

int parseType( string type ) {
  switch( type ) {
  case "L": return L;
  case "U": return U;
  case "D": return D;
  default: return -1;
  }
}

int judgeType( string str ) {
  if ( count( "ABCDEFGHIJKLMNOPQRSTUVWXYZ", str[ 0..1 ] ) > 0 ) {
	return U;
  } else if ( count( str, "_" ) > 0 ) {
	return D;
  } else {
	return L;
  }
}

string convertTypeToD( string input, int type ) {
  switch( type ){
  case L:
	return toLower( replace( input, regex( "([A-Z])", "g" ), "_$1" ) );
  case U:
	return toLower( replace( input, regex( "([A-Z])", "g" ), "_$1" )[ 1..$ ] );
  default:
	return input;
  }
}

string frontUpper( string input ) {
  return toUpper( input[ 0..1 ] ) ~ input[ 1..$ ];
}

string convertTypeFromD( string input, int type ) {
  switch( type ) {
  case U:
	return join( array( map!( frontUpper )( std.string.split( input, "_" ) ) ), "" );
  case L:
	auto tokens = std.string.split( input, "_" );
	return tokens[ 0 ] ~ join( array( map!( frontUpper )( tokens[ 1..$ ] ) ), "" );
  default:
	return input;
  }
}

void main()
{
  while ( true ) {
	string[] input = std.string.split( strip( readln ) );
	if ( input[ 0 ] == "EndOfInput" && input[ 1 ] == "X" ) {
	  break;
	}
	immutable int typeTo = parseType( input[ 1 ] );
	immutable int type = judgeType( input[ 0 ] );
	
	if ( typeTo == type ) {
	  writeln( input[ 0 ] );
	} else {
	  string origin = convertTypeToD( input[ 0 ], type );
	  writeln( convertTypeFromD( origin, typeTo ) );
	}
  }
}