// Aizu Vol-10 1044: CamelCase
// 2017.8.18 bal4u@uu

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

char n[130], t[10];
char ans[130];

int main()
{
	char *p, *q;

	while (scanf("%s%s", n, t) && t[0] != 'X') {
		p = n, q = ans;
		if (t[0] == 'U') {
			*q++ = toupper(*p++);
			while (*p) {
				while (*p && *p != '_') *q++ = *p++;
				if (*p == '_' && *(p + 1)) *q++ = toupper(*(p + 1)), p += 2;
			}
		} else if (t[0] == 'L') {
			*q++ = tolower(*p++);
			while (*p) {
				while (*p && *p != '_') *q++ = *p++;
				if (*p == '_' && *(p + 1)) *q++ = toupper(*(p + 1)), p += 2;
			}
		} else {
			*q++ = tolower(*p++);
			while (*p) {
				while (*p && !isupper(*p)) *q++ = *p++;
				if (isupper(*p)) *q++ = '_', *q++ = tolower(*p++);
			}
		}
		*q = 0;
		puts(ans);
	}
	return 0;
}