#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>

int
main (
  int   argc,
  char *argv[ ]
  )
{
  int i, j;

  for ( ; ; )
  {
    char s[ 128 ];
    char o;

    scanf ( " %s %c", s, &o );
    if ( o == 'X' ) break ;

    s[ 0 ] = tolower ( s[ 0 ] );
    j = 0;
    for ( i = 0; s[ i ] != '\0'; ++i )
    {
      if ( s[ i ] == '_' )
        s[ j++ ] = toupper ( s[ ++i ] );
      else
        s[ j++ ] = s[ i ];
    }
    s[ j ] = '\0';

    if ( o == 'U' )
    {
      s[ 0 ] = toupper ( s[ 0 ] );
      puts ( s );
    }
    else if ( o == 'L' )
    {
      puts ( s );
    }
    else
    {
      for ( i = 0; s[ i ] != '\0'; ++i )
      {
        if ( isupper ( s[ i ] ) )
          printf ( "_%c", tolower ( s[ i ] ) );
        else
          putchar ( s[ i ] );
      }
      puts ( "" );
    }
  }

  return ( EXIT_SUCCESS );
}