#K62882. Reverse Words in Sentences

    ID: 31630 Type: Default 1000ms 256MiB

Reverse Words in Sentences

Reverse Words in Sentences

Given a list of sentences, reverse the order of words in each sentence. For each sentence, if the sentence is given as: word1 word2 \(\dots\) wordn, then the result should be: wordn \(\dots\) word2 word1.

The input is read from standard input. The first line contains an integer \(n\) indicating the number of sentences, followed by \(n\) lines each representing a sentence. If a sentence is empty, simply output an empty line.

Mathematical Representation: For each sentence \(S = \{w_1, w_2, \dots, w_n\}\), the output should be \(S' = \{w_n, \dots, w_2, w_1\}\).

inputFormat

The first line of input contains an integer n (\(1 \le n \le 10^5\)), representing the number of sentences. The following n lines each contain a sentence consisting of words separated by spaces.

outputFormat

Output n lines where each line contains the corresponding sentence with its words in reversed order. There should be no extra spaces at the beginning or end of each line.

## sample
1
hello world
world hello