//* Problem  : I
//* Contest  : NEERC 2007
//* Type     : Solution
//* Date     : 2007.11.29
//* Author   : alt
//* Language : C++
//* Compiler : Microsoft Visual C++ 6.0

#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>

struct word{
	char w[40];
	char first, last;
	int skipped;
} a[100000]; int na;

char s[10000];
int valid[256], v2[256];

char tmp[2000];

int is_full(char *s)
{
	if (strlen(s) > 32) return 0;
	int f = 1, i;
	for (i = 0; s[i]; i++)
		if (s[i] < 'A' || s[i] > 'Z') f = 0;
	if (f) return 1;
	f = 1;
	for (i = 0; s[i]; i++)
		if (s[i] < 'a' || s[i] > 'z') f = 0;
	if (f) return 1;
	if (s[0] >= 'A' && s[0] <= 'Z') f = 1;
	for (i = 1; s[i]; i++)
		if (s[i] < 'a' || s[i] > 'z') f = 0;
	return f;
}

int is_abbreviation(char *s)
{
	int n;
	if ((n = strlen(s)) > 5) return 0;
	if (!((s[n-1] >= 'a' && s[n-1] <= 'z') || (s[n-1] >= 'A' && s[n-1] <= 'Z'))) return 0;
	if (s[1] == '0') return 0;
	for (int i = 1; i < n-1; i++)
		if (s[i] < '0' || s[i] > '9') return 0;
	if (sscanf(&s[1], "%d", &n) != 1) return 0;
	if (n > 30 || n < 2) return 0;
	return n;
}

int lower(char ch)
{
	if (ch >= 'a' && ch <= 'z') return 1;
	return 0;
}

int upper(char ch)
{
	if (ch >= 'A' && ch <= 'Z') return 1;
	return 0;
}

void print_word(char *s, int skipped, char *w)
{
	putchar(s[0]);
	if (upper(s[0]) && upper(s[strlen(s)-1]))
		for (int i = 1; i <= skipped; i++)
			putchar(w[i]+'A'-'a');
	else
		for (int i = 1; i <= skipped; i++)
			putchar(w[i]);
	putchar(s[strlen(s)-1]);
}

int find_word(char *s, int skipped)
{
	int f = -1; char first = s[0], last = s[strlen(s)-1];
	if (first >= 'A' && first <= 'Z') first = first - 'A' + 'a';
	if (last >= 'A' && last <= 'Z') last = last - 'A' + 'a';
	for (int i = 0; i < na; i++)
		if (a[i].first == first && a[i].last == last && skipped == a[i].skipped)
		{
			if ((f == -1) || (strcmp(a[f].w, a[i].w) == 0)) f = i;
				else return 0;
		}
	if (f == -1) return 0;
	//printf("%s", a[f].w);
	print_word(s, skipped, a[f].w);
	return 1;
}

void process_word()
{
	int k = is_abbreviation(tmp);
	if (k) 
	{
		if (!find_word(tmp, k)) printf("%s", tmp);
	}
	else if (is_full(tmp))
	{
		printf("%s", tmp);
		for (int i = 0; tmp[i]; i++)
			if (upper(tmp[i])) tmp[i] = tmp[i] - 'A' + 'a';
		int n = strlen(tmp);
		strcpy(a[na].w, tmp);
		a[na].first = tmp[0];
		a[na].last = tmp[n-1];
		a[na].skipped = n - 2;
		na++;
	}
	else printf("%s", tmp);
}

void process()
{
	int len = strlen(s), pos = 0, clen;
	while (pos < len)
	{
		while (s[pos] && !valid[s[pos]])
		{
			putchar(s[pos]);
			pos++;
		}
		if (pos >= len) break;
		clen = 0;
		while (v2[s[pos]])
		{
			tmp[clen] = s[pos];
			pos++;
			clen++;
		}
		tmp[clen] = 0;
		process_word();
	}
	putchar('\n');
}

int main()
{
	int i;
	for (i = 'a'; i <= 'z'; i++)
		v2[i] = v2[i+'A'-'a'] = valid[i] = valid[i+'A'-'a'] = 1;
	for (i = '0'; i <= '9'; i++)
		v2[i] = 1;
	while (!feof(stdin))
	{
		s[0] = 0; gets(s);
		process();
	}
	return 0;
}

 