/*--------------------------------------------------------------*/
/* ACM ICPC 2007-2008                                           */
/* Northeastern European Regional Contest                       */
/* St Petersburg - Barnaul - Tashkent - Batumi, November 28, 200*/
/*--------------------------------------------------------------*/
/* Problem I. I18n                                              */
/*--------------------------------------------------------------*/
/* Solution                                                     */
/*                                                              */
/* Author                Georgiy Korneev                        */
/*--------------------------------------------------------------*/
 
import java.io.*;
import java.util.*;
import static java.lang.Character.*;

public class i18n_gk {
    static final String AMBIGUITY = "*AMBIGUITY*";
    static Scanner in;
    static PrintWriter out;

    char firstChar(String word) {
        return word.charAt(0);
    }

    char lastChar(String word) {
        return word.charAt(word.length() - 1);
    }

    String abbreviate(String word) {        
        word = word.toLowerCase();
        return word.charAt(0) + "" + (word.length() - 2) + "" + lastChar(word);
    }

    String expand(String abbreviation, String word) {
        if (word == null || word.equals("*AMBIGUITY*")) {
            return abbreviation;
        }
        if (isUpperCase(lastChar(abbreviation))) {
            return word.toUpperCase();
        }
        if (isUpperCase(firstChar(abbreviation))) {
            return toUpperCase(firstChar(word)) + word.substring(1);
        }
        return word;
    }

    boolean isWord(String token) {
        if (token.length() <= 3) {
            return false;
        }
        for (char ch : token.toCharArray()) {
            if (!isLetter(ch)) {
                return false;
            }
        }
        return true;
    }

    void run() {
        Map<String, String> abbreviations = new HashMap<String, String>();
        StringBuilder sb = new StringBuilder();
        while (in.hasNext()) {
            String line = in.nextLine();
            StringTokenizer tokenizer = new StringTokenizer(line, " -,.\"():;!?", true);
            while (tokenizer.hasMoreTokens()) {
                String token = tokenizer.nextToken();
                if (isWord(token)) {
                    String abbreviation = abbreviate(token);
                    String prev = abbreviations.put(abbreviation, token.toLowerCase());
                    if (prev != null && !prev.equalsIgnoreCase(token)) {
                        abbreviations.put(abbreviation, AMBIGUITY);
                    }
                    sb.append(token);
                } else {
                    sb.append(expand(token, abbreviations.get(token.toLowerCase())));
                }
            }
            out.println(sb);
            sb.setLength(0);
        }
    }

    public static void main(String[] args) throws IOException {
        in = new Scanner(System.in);
        out = new PrintWriter(System.out);

        while (in.hasNext()) {
            new i18n_gk().run();
        }

        out.close();
        in.close();
    }
}
