#K69927. Reverse Words in a Sentence

    ID: 33195 Type: Default 1000ms 256MiB

Reverse Words in a Sentence

Reverse Words in a Sentence

You are given T test cases. Each test case contains one sentence. Your task is to reverse the order of the words in the given sentence. The words in the sentence are separated by spaces. Even if a sentence contains a single word or is empty, you should output it as is.

For example, given the sentence "Hello World", the output should be "World Hello".

The problem can be mathematically expressed as follows:

Given a sentence \(S = w_1\ w_2\ \ldots\ w_n\), produce \(S' = w_n\ w_{n-1}\ \ldots\ w_1\).

inputFormat

The input is read from STDIN and consists of:

  1. An integer T denoting the number of test cases.
  2. T lines, each containing a single sentence. A sentence is a sequence of words separated by spaces and may be empty.

outputFormat

For each test case, output the sentence with the order of its words reversed. Each result should be printed on a new line to STDOUT.

## sample
3
Hello World
The quick brown fox
Coding is fun
World Hello

fox brown quick The fun is Coding

</p>