public static void swapWords(Text text) {
        log.trace("Subtask N5");
        LinkedList<Sentence> allElements = (LinkedList<Sentence>) text.getAllElements();
        for (Sentence sentenceOrListing : allElements) {
            if (sentenceOrListing.getClass() != Listing.class) {
                int indexFirst = 0;
                int indexLast = 0;
                Sentence sentence = (Sentence) sentenceOrListing;
                List<SentencePart> sentenceParts = sentence.getAllElements();
                for (int i = 0; i < sentenceParts.size(); i++) {
                    SentencePart part = sentenceParts.get(i);
                    if (part instanceof Word) {
                        indexFirst = i;
                        break;
                    }
                }
                for (int i = sentenceParts.size() - 1; i >= 0; i--) {
                    SentencePart part = sentenceParts.get(i);
                    if (part instanceof Word) {
                        indexLast = i;
                        break;
                    }
                }
                Collections.swap(sentenceParts, indexFirst, indexLast);
            }
        }
    }